1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SV_SALGDI_HXX 25 #define _SV_SALGDI_HXX 26 27 #include "tools/string.hxx" 28 #include "rtl/ustring.hxx" 29 #include "vcl/sv.h" 30 #include "vcl/dllapi.h" 31 #include "vcl/salgtype.hxx" 32 #include "vos/thread.hxx" 33 #include "vcl/outdev.hxx" 34 #include "vcl/salnativewidgets.hxx" 35 36 #include <map> 37 38 class ImplDevFontList; 39 class SalBitmap; 40 class ImplFontSelectData; 41 class ImplFontMetricData; 42 struct ImplKernPairData; 43 class ImplFontData; 44 class ImplFontCharMap; 45 class SalLayout; 46 class ImplLayoutArgs; 47 class Rectangle; 48 class FontSubsetInfo; 49 class OutputDevice; 50 class ServerFontLayout; 51 struct SystemGraphicsData; 52 struct SystemFontData; 53 54 namespace basegfx { 55 class B2DVector; 56 class B2DPolygon; 57 class B2DPolyPolygon; 58 } 59 60 // --------------------- 61 // - SalGraphics-Codes - 62 // --------------------- 63 64 #define SAL_SETFONT_REMOVEANDMATCHNEW ((sal_uInt16)0x0001) 65 #define SAL_SETFONT_USEDRAWTEXT ((sal_uInt16)0x0002) 66 #define SAL_SETFONT_USEDRAWTEXTARRAY ((sal_uInt16)0x0004) 67 #define SAL_SETFONT_UNICODE ((sal_uInt16)0x0008) 68 #define SAL_SETFONT_BADFONT ((sal_uInt16)0x1000) 69 70 #define SAL_COPYAREA_WINDOWINVALIDATE ((sal_uInt16)0x0001) 71 72 // ------------------- 73 // - common typedefs - 74 // ------------------- 75 76 typedef sal_Unicode sal_Ucs; // TODO: use sal_UCS4 instead of sal_Unicode 77 typedef std::map< sal_Ucs, sal_Int32 > Ucs2SIntMap; 78 typedef std::map< sal_Ucs, sal_uInt32 > Ucs2UIntMap; 79 typedef std::map< sal_Ucs, rtl::OString > Ucs2OStrMap; 80 typedef std::vector< sal_Int32 > Int32Vector; 81 82 // --------------- 83 // - SalGraphics - 84 // --------------- 85 86 // note: if you add any new methods to class SalGraphics using coordinates 87 // make sure they have a corresponding protected pure virtual method 88 // which has to be implemented by the platform dependent part. 89 // Add a method that performs coordinate mirroring if required, (see 90 // existing methods as sample) and then calls the equivalent pure method. 91 92 // note: all positions are in pixel and relative to 93 // the top/left-position of the virtual output area 94 95 class VCL_PLUGIN_PUBLIC SalGraphics 96 { 97 int m_nLayout; // 0: mirroring off, 1: mirror x-axis 98 99 protected: 100 // flags which hold the SetAntialiasing() value from OutputDevice 101 bool m_bAntiAliasB2DDraw; 102 103 public: 104 // get/set AA 105 void setAntiAliasB2DDraw(bool bNew) { m_bAntiAliasB2DDraw = bNew; } 106 bool getAntiAliasB2DDraw() const { return m_bAntiAliasB2DDraw; } 107 108 SalGraphics(); 109 virtual ~SalGraphics(); 110 111 protected: 112 virtual bool setClipRegion( const Region& ) = 0; 113 // draw --> LineColor and FillColor and RasterOp and ClipRegion 114 virtual void drawPixel( long nX, long nY ) = 0; 115 virtual void drawPixel( long nX, long nY, SalColor nSalColor ) = 0; 116 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) = 0; 117 virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) = 0; 118 virtual void drawPolyLine( sal_uLong nPoints, const SalPoint* pPtAry ) = 0; 119 virtual void drawPolygon( sal_uLong nPoints, const SalPoint* pPtAry ) = 0; 120 virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) = 0; 121 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ) = 0; 122 virtual bool drawPolyLine( 123 const ::basegfx::B2DPolygon&, 124 double fTransparency, 125 const ::basegfx::B2DVector& rLineWidths, 126 basegfx::B2DLineJoin, 127 com::sun::star::drawing::LineCap) = 0; 128 virtual sal_Bool drawPolyLineBezier( sal_uLong nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ) = 0; 129 virtual sal_Bool drawPolygonBezier( sal_uLong nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ) = 0; 130 virtual sal_Bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const sal_uInt8* const* pFlgAry ) = 0; 131 132 // CopyArea --> No RasterOp, but ClipRegion 133 virtual void copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, 134 long nSrcHeight, sal_uInt16 nFlags ) = 0; 135 136 // CopyBits and DrawBitmap --> RasterOp and ClipRegion 137 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics 138 virtual void copyBits( const SalTwoRect* pPosAry, SalGraphics* pSrcGraphics ) = 0; 139 virtual void drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rSalBitmap ) = 0; 140 virtual void drawBitmap( const SalTwoRect* pPosAry, 141 const SalBitmap& rSalBitmap, 142 SalColor nTransparentColor ) = 0; 143 virtual void drawBitmap( const SalTwoRect* pPosAry, 144 const SalBitmap& rSalBitmap, 145 const SalBitmap& rMaskBitmap ) = 0; 146 virtual void drawMask( const SalTwoRect* pPosAry, 147 const SalBitmap& rSalBitmap, 148 SalColor nMaskColor ) = 0; 149 150 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ) = 0; 151 virtual SalColor getPixel( long nX, long nY ) = 0; 152 153 // invert --> ClipRegion (only Windows or VirDevs) 154 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) = 0; 155 virtual void invert( sal_uLong nPoints, const SalPoint* pPtAry, SalInvert nFlags ) = 0; 156 157 virtual sal_Bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize ) = 0; 158 159 // native widget rendering methods that require mirroring 160 virtual sal_Bool hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 161 const Point& aPos, sal_Bool& rIsInside ); 162 virtual sal_Bool drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 163 ControlState nState, const ImplControlValue& aValue, 164 const rtl::OUString& aCaption ); 165 virtual sal_Bool drawNativeControlText( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 166 ControlState nState, const ImplControlValue& aValue, 167 const rtl::OUString& aCaption ); 168 virtual sal_Bool getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState, 169 const ImplControlValue& aValue, const rtl::OUString& aCaption, 170 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion ); 171 172 /** Render bitmap with alpha channel 173 174 @param rSourceBitmap 175 Source bitmap to blit 176 177 @param rAlphaBitmap 178 Alpha channel to use for blitting 179 180 @return true, if the operation succeeded, and false 181 otherwise. In this case, clients should try to emulate alpha 182 compositing themselves 183 */ 184 virtual bool drawAlphaBitmap( const SalTwoRect&, 185 const SalBitmap& rSourceBitmap, 186 const SalBitmap& rAlphaBitmap ) = 0; 187 /** Render solid rectangle with given transparency 188 189 @param nTransparency 190 Transparency value (0-255) to use. 0 blits and opaque, 255 a 191 fully transparent rectangle 192 */ 193 virtual bool drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency ) = 0; 194 195 public: 196 // public SalGraphics methods, the interface to the independent vcl part 197 198 // get device resolution 199 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) = 0; 200 // get the depth of the device 201 virtual sal_uInt16 GetBitCount() = 0; 202 // get the width of the device 203 virtual long GetGraphicsWidth() const = 0; 204 205 // set the clip region to empty 206 virtual void ResetClipRegion() = 0; 207 208 // set the line color to transparent (= don't draw lines) 209 virtual void SetLineColor() = 0; 210 // set the line color to a specific color 211 virtual void SetLineColor( SalColor nSalColor ) = 0; 212 // set the fill color to transparent (= don't fill) 213 virtual void SetFillColor() = 0; 214 // set the fill color to a specific color, shapes will be 215 // filled accordingly 216 virtual void SetFillColor( SalColor nSalColor ) = 0; 217 // enable/disable XOR drawing 218 virtual void SetXORMode( bool bSet, bool bInvertOnly ) = 0; 219 // set line color for raster operations 220 virtual void SetROPLineColor( SalROPColor nROPColor ) = 0; 221 // set fill color for raster operations 222 virtual void SetROPFillColor( SalROPColor nROPColor ) = 0; 223 // set the text color to a specific color 224 virtual void SetTextColor( SalColor nSalColor ) = 0; 225 // set the font 226 virtual sal_uInt16 SetFont( ImplFontSelectData*, int nFallbackLevel ) = 0; 227 // release the fonts 228 void ReleaseFonts() { SetFont( NULL, 0 ); } 229 // get the current font's metrics 230 virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel = 0 ) = 0; 231 232 // get kernign pairs of the current font 233 // return only PairCount if (pKernPairs == NULL) 234 virtual sal_uLong GetKernPairs( sal_uLong nMaxPairCount, ImplKernPairData* ) = 0; 235 // get the repertoire of the current font 236 virtual const ImplFontCharMap* GetImplFontCharMap() const = 0; 237 // graphics must fill supplied font list 238 virtual void GetDevFontList( ImplDevFontList* ) = 0; 239 // graphics should call ImplAddDevFontSubstitute on supplied 240 // OutputDevice for all its device specific preferred font substitutions 241 virtual void GetDevFontSubstList( OutputDevice* ) = 0; 242 virtual bool AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName ) = 0; 243 // CreateFontSubset: a method to get a subset of glyhps of a font 244 // inside a new valid font file 245 // returns sal_True if creation of subset was successfull 246 // parameters: rToFile: contains a osl file URL to write the subset to 247 // pFont: describes from which font to create a subset 248 // pGlyphIDs: the glyph ids to be extracted 249 // pEncoding: the character code corresponding to each glyph 250 // pWidths: the advance widths of the correspoding glyphs (in PS font units) 251 // nGlyphs: the number of glyphs 252 // rInfo: additional outgoing information 253 // implementation note: encoding 0 with glyph id 0 should be added implicitly 254 // as "undefined character" 255 virtual sal_Bool CreateFontSubset( const rtl::OUString& rToFile, 256 const ImplFontData* pFont, 257 sal_Int32* pGlyphIDs, 258 sal_uInt8* pEncoding, 259 sal_Int32* pWidths, 260 int nGlyphs, 261 FontSubsetInfo& rInfo // out parameter 262 ) = 0; 263 264 // GetFontEncodingVector: a method to get the encoding map Unicode 265 // to font encoded character; this is only used for type1 fonts and 266 // may return NULL in case of unknown encoding vector 267 // if ppNonEncoded is set and non encoded characters (that is type1 268 // glyphs with only a name) exist it is set to the corresponding 269 // map for non encoded glyphs; the encoding vector contains -1 270 // as encoding for these cases 271 virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded ) = 0; 272 273 // GetEmbedFontData: gets the font data for a font marked 274 // embeddable by GetDevFontList or NULL in case of error 275 // parameters: pFont: describes the font in question 276 // pUnicodes: contains the Unicodes assigned to 277 // code points 0 to 255; must contain at least 256 members 278 // pWidths: the widths of all glyphs from char code 0 to 255 279 // pWidths MUST support at least 256 members; 280 // rInfo: additional outgoing information 281 // pDataLen: out parameter, contains the byte length of the returned buffer 282 virtual const void* GetEmbedFontData( const ImplFontData* pFont, 283 const sal_Ucs* pUnicodes, 284 sal_Int32* pWidths, 285 FontSubsetInfo& rInfo, 286 long* pDataLen ) = 0; 287 // frees the font data again 288 virtual void FreeEmbedFontData( const void* pData, long nDataLen ) = 0; 289 290 // get the same widths as in CreateFontSubset and GetEmbedFontData 291 // in case of an embeddable font also fill the mapping 292 // between unicode and glyph id 293 // leave widths vector and mapping untouched in case of failure 294 virtual void GetGlyphWidths( const ImplFontData* pFont, 295 bool bVertical, 296 Int32Vector& rWidths, 297 Ucs2UIntMap& rUnicodeEnc ) = 0; 298 299 virtual sal_Bool GetGlyphBoundRect( long nIndex, Rectangle& ) = 0; 300 virtual sal_Bool GetGlyphOutline( long nIndex, basegfx::B2DPolyPolygon& ) = 0; 301 302 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0; 303 virtual void DrawServerFontLayout( const ServerFontLayout& ) = 0; 304 /** Filter text from DrawText commands in a device specific manner 305 <p> 306 This function allows a device (or rather the corresponding SalGraphics 307 implementation) to prevent text portions from being drawn. This currently 308 is used only for filtering out the fax number in a document that is printed 309 to one of psprint's specialized "fax" printers. 310 </p> 311 312 @param rOrigText 313 The original text 314 315 @param rNewText 316 A String that will be filled with the adjusted version 317 318 @param nIndex 319 The index inside <code>rOrigText</code> that marks the first draw character 320 321 @param rLen 322 in: length of text beginning at <code>nIndex</code> to be drawn 323 out: length of <code>rNewText</code> containing the substituted text 324 325 @param rCutStart 326 out: index at which the cutout portion of <code>rOrigText</code> begins 327 328 @param rCutStop 329 out: index at which the cutout portion of <code>rOrigText</code> ends 330 331 @returns 332 true: a substitution has taken place and rNewText rLen, rCutStart and rCutStop have been filled accordingly 333 false: no substitution has taken place, rNewText, rLen, rCutStart, rCutStop remain unchanged 334 */ 335 virtual bool filterText( const String& rOrigText, String& rNewText, xub_StrLen nIndex, xub_StrLen& rLen, xub_StrLen& rCutStart, xub_StrLen& rCutStop ); 336 337 virtual bool supportsOperation( OutDevSupportType ) const = 0; 338 339 // mirroring specifica 340 int GetLayout() { return m_nLayout; } 341 void SetLayout( int aLayout ) { m_nLayout = aLayout;} 342 343 void mirror( long& nX, const OutputDevice *pOutDev, bool bBack = false ) const; 344 void mirror( long& nX, long& nWidth, const OutputDevice *pOutDev, bool bBack = false ) const; 345 sal_Bool mirror( sal_uInt32 nPoints, const SalPoint *pPtAry, SalPoint *pPtAry2, const OutputDevice *pOutDev, bool bBack = false ) const; 346 void mirror( Rectangle& rRect, const OutputDevice*, bool bBack = false ) const; 347 void mirror( Region& rRgn, const OutputDevice *pOutDev, bool bBack = false ) const; 348 void mirror( ControlType,const ImplControlValue&,const OutputDevice*,bool bBack = false) const; 349 basegfx::B2DPoint mirror( const basegfx::B2DPoint& i_rPoint, const OutputDevice *pOutDev, bool bBack = false ) const; 350 basegfx::B2DPolygon mirror( const basegfx::B2DPolygon& i_rPoly, const OutputDevice *pOutDev, bool bBack = false ) const; 351 basegfx::B2DPolyPolygon mirror( const basegfx::B2DPolyPolygon& i_rPoly, const OutputDevice *pOutDev, bool bBack = false ) const; 352 353 // non virtual methods; these do possible coordinate mirroring and 354 // then delegate to protected virtual methods 355 bool SetClipRegion( const Region&, const OutputDevice *pOutDev ); 356 357 // draw --> LineColor and FillColor and RasterOp and ClipRegion 358 void DrawPixel( long nX, long nY, const OutputDevice *pOutDev ); 359 void DrawPixel( long nX, long nY, SalColor nSalColor, const OutputDevice *pOutDev ); 360 void DrawLine( long nX1, long nY1, long nX2, long nY2, const OutputDevice *pOutDev ); 361 void DrawRect( long nX, long nY, long nWidth, long nHeight, const OutputDevice *pOutDev ); 362 void DrawPolyLine( sal_uLong nPoints, const SalPoint* pPtAry, const OutputDevice *pOutDev ); 363 void DrawPolygon( sal_uLong nPoints, const SalPoint* pPtAry, const OutputDevice *pOutDev ); 364 void DrawPolyPolygon( sal_uInt32 nPoly, 365 const sal_uInt32* pPoints, 366 PCONSTSALPOINT* pPtAry, 367 const OutputDevice *pOutDev ); 368 bool DrawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency, const OutputDevice* ); 369 370 bool DrawPolyLine( 371 const basegfx::B2DPolygon& i_rPolygon, 372 double i_fTransparency, 373 const basegfx::B2DVector& i_rLineWidth, 374 basegfx::B2DLineJoin i_eLineJoin, 375 com::sun::star::drawing::LineCap i_eLineCap, 376 const OutputDevice* i_pOutDev); 377 378 sal_Bool DrawPolyLineBezier( sal_uLong nPoints, 379 const SalPoint* pPtAry, 380 const sal_uInt8* pFlgAry, 381 const OutputDevice *pOutDev ); 382 sal_Bool DrawPolygonBezier( sal_uLong nPoints, 383 const SalPoint* pPtAry, 384 const sal_uInt8* pFlgAry, 385 const OutputDevice *pOutDev ); 386 sal_Bool DrawPolyPolygonBezier( sal_uInt32 nPoly, 387 const sal_uInt32* pPoints, 388 const SalPoint* const* pPtAry, 389 const sal_uInt8* const* pFlgAry, 390 const OutputDevice *pOutDev ); 391 392 // CopyArea --> No RasterOp, but ClipRegion 393 void CopyArea( long nDestX, 394 long nDestY, 395 long nSrcX, 396 long nSrcY, 397 long nSrcWidth, 398 long nSrcHeight, 399 sal_uInt16 nFlags, 400 const OutputDevice *pOutDev ); 401 402 // CopyBits and DrawBitmap --> RasterOp and ClipRegion 403 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics 404 void CopyBits( const SalTwoRect* pPosAry, 405 SalGraphics* pSrcGraphics, 406 const OutputDevice *pOutDev, 407 const OutputDevice *pSrcOutDev ); 408 void DrawBitmap( const SalTwoRect* pPosAry, 409 const SalBitmap& rSalBitmap, 410 const OutputDevice *pOutDev ); 411 void DrawBitmap( const SalTwoRect* pPosAry, 412 const SalBitmap& rSalBitmap, 413 SalColor nTransparentColor, 414 const OutputDevice *pOutDev ); 415 void DrawBitmap( const SalTwoRect* pPosAry, 416 const SalBitmap& rSalBitmap, 417 const SalBitmap& rTransparentBitmap, 418 const OutputDevice *pOutDev ); 419 420 void DrawMask( const SalTwoRect* pPosAry, 421 const SalBitmap& rSalBitmap, 422 SalColor nMaskColor, 423 const OutputDevice *pOutDev ); 424 425 SalBitmap* GetBitmap( long nX, long nY, long nWidth, long nHeight, const OutputDevice *pOutDev ); 426 SalColor GetPixel( long nX, long nY, const OutputDevice *pOutDev ); 427 428 // invert --> ClipRegion (only Windows) 429 void Invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags, const OutputDevice *pOutDev ); 430 void Invert( sal_uLong nPoints, const SalPoint* pPtAry, SalInvert nFlags, const OutputDevice *pOutDev ); 431 432 sal_Bool DrawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize, const OutputDevice *pOutDev ); 433 434 //------------------------------------- 435 // Native Widget Rendering functions 436 //------------------------------------- 437 438 // Query the platform layer for control support 439 virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart ); 440 441 // Query the native control to determine if it was acted upon 442 sal_Bool HitTestNativeControl( ControlType nType, 443 ControlPart nPart, 444 const Rectangle& rControlRegion, 445 const Point& aPos, 446 sal_Bool& rIsInside, 447 const OutputDevice *pOutDev ); 448 449 // Request rendering of a particular control and/or part 450 sal_Bool DrawNativeControl( ControlType nType, 451 ControlPart nPart, 452 const Rectangle& rControlRegion, 453 ControlState nState, 454 const ImplControlValue& aValue, 455 const rtl::OUString& aCaption, 456 const OutputDevice *pOutDev ); 457 458 // Request rendering of a caption string for a control 459 sal_Bool DrawNativeControlText( ControlType nType, 460 ControlPart nPart, 461 const Rectangle& rControlRegion, 462 ControlState nState, 463 const ImplControlValue& aValue, 464 const rtl::OUString& aCaption, 465 const OutputDevice *pOutDev ); 466 467 // Query the native control's actual drawing region (including adornment) 468 sal_Bool GetNativeControlRegion( ControlType nType, 469 ControlPart nPart, 470 const Rectangle& rControlRegion, 471 ControlState nState, 472 const ImplControlValue& aValue, 473 const rtl::OUString& aCaption, 474 Rectangle &rNativeBoundingRegion, 475 Rectangle &rNativeContentRegion, 476 const OutputDevice *pOutDev ); 477 478 static void AddDevFontSubstitute( OutputDevice* pOutDev, 479 const String& rFontName, 480 const String& rReplaceFontName, 481 sal_uInt16 nFlags = 0 ); 482 483 bool DrawAlphaBitmap( const SalTwoRect&, 484 const SalBitmap& rSourceBitmap, 485 const SalBitmap& rAlphaBitmap, 486 const OutputDevice *pOutDev ); 487 488 bool DrawAlphaRect( long nX, long nY, long nWidth, long nHeight, 489 sal_uInt8 nTransparency, const OutputDevice *pOutDev ); 490 491 virtual SystemGraphicsData GetGraphicsData() const = 0; 492 virtual SystemFontData GetSysFontData( int nFallbacklevel ) const = 0; 493 }; 494 495 #endif // _SV_SALGDI_HXX 496