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( const ::basegfx::B2DPolygon&, double fTransparency, const ::basegfx::B2DVector& rLineWidths, basegfx::B2DLineJoin ) = 0; 123 virtual sal_Bool drawPolyLineBezier( sal_uLong nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ) = 0; 124 virtual sal_Bool drawPolygonBezier( sal_uLong nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ) = 0; 125 virtual sal_Bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const sal_uInt8* const* pFlgAry ) = 0; 126 127 // CopyArea --> No RasterOp, but ClipRegion 128 virtual void copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, 129 long nSrcHeight, sal_uInt16 nFlags ) = 0; 130 131 // CopyBits and DrawBitmap --> RasterOp and ClipRegion 132 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics 133 virtual void copyBits( const SalTwoRect* pPosAry, SalGraphics* pSrcGraphics ) = 0; 134 virtual void drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rSalBitmap ) = 0; 135 virtual void drawBitmap( const SalTwoRect* pPosAry, 136 const SalBitmap& rSalBitmap, 137 SalColor nTransparentColor ) = 0; 138 virtual void drawBitmap( const SalTwoRect* pPosAry, 139 const SalBitmap& rSalBitmap, 140 const SalBitmap& rMaskBitmap ) = 0; 141 virtual void drawMask( const SalTwoRect* pPosAry, 142 const SalBitmap& rSalBitmap, 143 SalColor nMaskColor ) = 0; 144 145 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ) = 0; 146 virtual SalColor getPixel( long nX, long nY ) = 0; 147 148 // invert --> ClipRegion (only Windows or VirDevs) 149 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) = 0; 150 virtual void invert( sal_uLong nPoints, const SalPoint* pPtAry, SalInvert nFlags ) = 0; 151 152 virtual sal_Bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize ) = 0; 153 154 // native widget rendering methods that require mirroring 155 virtual sal_Bool hitTestNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 156 const Point& aPos, sal_Bool& rIsInside ); 157 virtual sal_Bool drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 158 ControlState nState, const ImplControlValue& aValue, 159 const rtl::OUString& aCaption ); 160 virtual sal_Bool drawNativeControlText( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, 161 ControlState nState, const ImplControlValue& aValue, 162 const rtl::OUString& aCaption ); 163 virtual sal_Bool getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState, 164 const ImplControlValue& aValue, const rtl::OUString& aCaption, 165 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion ); 166 167 /** Render bitmap with alpha channel 168 169 @param rSourceBitmap 170 Source bitmap to blit 171 172 @param rAlphaBitmap 173 Alpha channel to use for blitting 174 175 @return true, if the operation succeeded, and false 176 otherwise. In this case, clients should try to emulate alpha 177 compositing themselves 178 */ 179 virtual bool drawAlphaBitmap( const SalTwoRect&, 180 const SalBitmap& rSourceBitmap, 181 const SalBitmap& rAlphaBitmap ) = 0; 182 /** Render solid rectangle with given transparency 183 184 @param nTransparency 185 Transparency value (0-255) to use. 0 blits and opaque, 255 a 186 fully transparent rectangle 187 */ 188 virtual bool drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency ) = 0; 189 190 public: 191 // public SalGraphics methods, the interface to the independent vcl part 192 193 // get device resolution 194 virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) = 0; 195 // get the depth of the device 196 virtual sal_uInt16 GetBitCount() = 0; 197 // get the width of the device 198 virtual long GetGraphicsWidth() const = 0; 199 200 // set the clip region to empty 201 virtual void ResetClipRegion() = 0; 202 203 // set the line color to transparent (= don't draw lines) 204 virtual void SetLineColor() = 0; 205 // set the line color to a specific color 206 virtual void SetLineColor( SalColor nSalColor ) = 0; 207 // set the fill color to transparent (= don't fill) 208 virtual void SetFillColor() = 0; 209 // set the fill color to a specific color, shapes will be 210 // filled accordingly 211 virtual void SetFillColor( SalColor nSalColor ) = 0; 212 // enable/disable XOR drawing 213 virtual void SetXORMode( bool bSet, bool bInvertOnly ) = 0; 214 // set line color for raster operations 215 virtual void SetROPLineColor( SalROPColor nROPColor ) = 0; 216 // set fill color for raster operations 217 virtual void SetROPFillColor( SalROPColor nROPColor ) = 0; 218 // set the text color to a specific color 219 virtual void SetTextColor( SalColor nSalColor ) = 0; 220 // set the font 221 virtual sal_uInt16 SetFont( ImplFontSelectData*, int nFallbackLevel ) = 0; 222 // release the fonts 223 void ReleaseFonts() { SetFont( NULL, 0 ); } 224 // get the current font's metrics 225 virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel = 0 ) = 0; 226 227 // get kernign pairs of the current font 228 // return only PairCount if (pKernPairs == NULL) 229 virtual sal_uLong GetKernPairs( sal_uLong nMaxPairCount, ImplKernPairData* ) = 0; 230 // get the repertoire of the current font 231 virtual const ImplFontCharMap* GetImplFontCharMap() const = 0; 232 // graphics must fill supplied font list 233 virtual void GetDevFontList( ImplDevFontList* ) = 0; 234 // graphics should call ImplAddDevFontSubstitute on supplied 235 // OutputDevice for all its device specific preferred font substitutions 236 virtual void GetDevFontSubstList( OutputDevice* ) = 0; 237 virtual bool AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName ) = 0; 238 // CreateFontSubset: a method to get a subset of glyhps of a font 239 // inside a new valid font file 240 // returns sal_True if creation of subset was successfull 241 // parameters: rToFile: contains a osl file URL to write the subset to 242 // pFont: describes from which font to create a subset 243 // pGlyphIDs: the glyph ids to be extracted 244 // pEncoding: the character code corresponding to each glyph 245 // pWidths: the advance widths of the correspoding glyphs (in PS font units) 246 // nGlyphs: the number of glyphs 247 // rInfo: additional outgoing information 248 // implementation note: encoding 0 with glyph id 0 should be added implicitly 249 // as "undefined character" 250 virtual sal_Bool CreateFontSubset( const rtl::OUString& rToFile, 251 const ImplFontData* pFont, 252 sal_Int32* pGlyphIDs, 253 sal_uInt8* pEncoding, 254 sal_Int32* pWidths, 255 int nGlyphs, 256 FontSubsetInfo& rInfo // out parameter 257 ) = 0; 258 259 // GetFontEncodingVector: a method to get the encoding map Unicode 260 // to font encoded character; this is only used for type1 fonts and 261 // may return NULL in case of unknown encoding vector 262 // if ppNonEncoded is set and non encoded characters (that is type1 263 // glyphs with only a name) exist it is set to the corresponding 264 // map for non encoded glyphs; the encoding vector contains -1 265 // as encoding for these cases 266 virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded ) = 0; 267 268 // GetEmbedFontData: gets the font data for a font marked 269 // embeddable by GetDevFontList or NULL in case of error 270 // parameters: pFont: describes the font in question 271 // pUnicodes: contains the Unicodes assigned to 272 // code points 0 to 255; must contain at least 256 members 273 // pWidths: the widths of all glyphs from char code 0 to 255 274 // pWidths MUST support at least 256 members; 275 // rInfo: additional outgoing information 276 // pDataLen: out parameter, contains the byte length of the returned buffer 277 virtual const void* GetEmbedFontData( const ImplFontData* pFont, 278 const sal_Ucs* pUnicodes, 279 sal_Int32* pWidths, 280 FontSubsetInfo& rInfo, 281 long* pDataLen ) = 0; 282 // frees the font data again 283 virtual void FreeEmbedFontData( const void* pData, long nDataLen ) = 0; 284 285 // get the same widths as in CreateFontSubset and GetEmbedFontData 286 // in case of an embeddable font also fill the mapping 287 // between unicode and glyph id 288 // leave widths vector and mapping untouched in case of failure 289 virtual void GetGlyphWidths( const ImplFontData* pFont, 290 bool bVertical, 291 Int32Vector& rWidths, 292 Ucs2UIntMap& rUnicodeEnc ) = 0; 293 294 virtual sal_Bool GetGlyphBoundRect( long nIndex, Rectangle& ) = 0; 295 virtual sal_Bool GetGlyphOutline( long nIndex, basegfx::B2DPolyPolygon& ) = 0; 296 297 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0; 298 virtual void DrawServerFontLayout( const ServerFontLayout& ) = 0; 299 /** Filter text from DrawText commands in a device specific manner 300 <p> 301 This function allows a device (or rather the corresponding SalGraphics 302 implementation) to prevent text portions from being drawn. This currently 303 is used only for filtering out the fax number in a document that is printed 304 to one of psprint's specialized "fax" printers. 305 </p> 306 307 @param rOrigText 308 The original text 309 310 @param rNewText 311 A String that will be filled with the adjusted version 312 313 @param nIndex 314 The index inside <code>rOrigText</code> that marks the first draw character 315 316 @param rLen 317 in: length of text beginning at <code>nIndex</code> to be drawn 318 out: length of <code>rNewText</code> containing the substituted text 319 320 @param rCutStart 321 out: index at which the cutout portion of <code>rOrigText</code> begins 322 323 @param rCutStop 324 out: index at which the cutout portion of <code>rOrigText</code> ends 325 326 @returns 327 true: a substitution has taken place and rNewText rLen, rCutStart and rCutStop have been filled accordingly 328 false: no substitution has taken place, rNewText, rLen, rCutStart, rCutStop remain unchanged 329 */ 330 virtual bool filterText( const String& rOrigText, String& rNewText, xub_StrLen nIndex, xub_StrLen& rLen, xub_StrLen& rCutStart, xub_StrLen& rCutStop ); 331 332 virtual bool supportsOperation( OutDevSupportType ) const = 0; 333 334 // mirroring specifica 335 int GetLayout() { return m_nLayout; } 336 void SetLayout( int aLayout ) { m_nLayout = aLayout;} 337 338 void mirror( long& nX, const OutputDevice *pOutDev, bool bBack = false ) const; 339 void mirror( long& nX, long& nWidth, const OutputDevice *pOutDev, bool bBack = false ) const; 340 sal_Bool mirror( sal_uInt32 nPoints, const SalPoint *pPtAry, SalPoint *pPtAry2, const OutputDevice *pOutDev, bool bBack = false ) const; 341 void mirror( Rectangle& rRect, const OutputDevice*, bool bBack = false ) const; 342 void mirror( Region& rRgn, const OutputDevice *pOutDev, bool bBack = false ) const; 343 void mirror( ControlType,const ImplControlValue&,const OutputDevice*,bool bBack = false) const; 344 basegfx::B2DPoint mirror( const basegfx::B2DPoint& i_rPoint, const OutputDevice *pOutDev, bool bBack = false ) const; 345 basegfx::B2DPolygon mirror( const basegfx::B2DPolygon& i_rPoly, const OutputDevice *pOutDev, bool bBack = false ) const; 346 basegfx::B2DPolyPolygon mirror( const basegfx::B2DPolyPolygon& i_rPoly, const OutputDevice *pOutDev, bool bBack = false ) const; 347 348 // non virtual methods; these do possible coordinate mirroring and 349 // then delegate to protected virtual methods 350 bool SetClipRegion( const Region&, const OutputDevice *pOutDev ); 351 352 // draw --> LineColor and FillColor and RasterOp and ClipRegion 353 void DrawPixel( long nX, long nY, const OutputDevice *pOutDev ); 354 void DrawPixel( long nX, long nY, SalColor nSalColor, const OutputDevice *pOutDev ); 355 void DrawLine( long nX1, long nY1, long nX2, long nY2, const OutputDevice *pOutDev ); 356 void DrawRect( long nX, long nY, long nWidth, long nHeight, const OutputDevice *pOutDev ); 357 void DrawPolyLine( sal_uLong nPoints, const SalPoint* pPtAry, const OutputDevice *pOutDev ); 358 void DrawPolygon( sal_uLong nPoints, const SalPoint* pPtAry, const OutputDevice *pOutDev ); 359 void DrawPolyPolygon( sal_uInt32 nPoly, 360 const sal_uInt32* pPoints, 361 PCONSTSALPOINT* pPtAry, 362 const OutputDevice *pOutDev ); 363 bool DrawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency, const OutputDevice* ); 364 bool DrawPolyLine( const basegfx::B2DPolygon&, double fTransparency, const basegfx::B2DVector& rLineWidths, basegfx::B2DLineJoin, const OutputDevice* ); 365 sal_Bool DrawPolyLineBezier( sal_uLong nPoints, 366 const SalPoint* pPtAry, 367 const sal_uInt8* pFlgAry, 368 const OutputDevice *pOutDev ); 369 sal_Bool DrawPolygonBezier( sal_uLong nPoints, 370 const SalPoint* pPtAry, 371 const sal_uInt8* pFlgAry, 372 const OutputDevice *pOutDev ); 373 sal_Bool DrawPolyPolygonBezier( sal_uInt32 nPoly, 374 const sal_uInt32* pPoints, 375 const SalPoint* const* pPtAry, 376 const sal_uInt8* const* pFlgAry, 377 const OutputDevice *pOutDev ); 378 379 // CopyArea --> No RasterOp, but ClipRegion 380 void CopyArea( long nDestX, 381 long nDestY, 382 long nSrcX, 383 long nSrcY, 384 long nSrcWidth, 385 long nSrcHeight, 386 sal_uInt16 nFlags, 387 const OutputDevice *pOutDev ); 388 389 // CopyBits and DrawBitmap --> RasterOp and ClipRegion 390 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics 391 void CopyBits( const SalTwoRect* pPosAry, 392 SalGraphics* pSrcGraphics, 393 const OutputDevice *pOutDev, 394 const OutputDevice *pSrcOutDev ); 395 void DrawBitmap( const SalTwoRect* pPosAry, 396 const SalBitmap& rSalBitmap, 397 const OutputDevice *pOutDev ); 398 void DrawBitmap( const SalTwoRect* pPosAry, 399 const SalBitmap& rSalBitmap, 400 SalColor nTransparentColor, 401 const OutputDevice *pOutDev ); 402 void DrawBitmap( const SalTwoRect* pPosAry, 403 const SalBitmap& rSalBitmap, 404 const SalBitmap& rTransparentBitmap, 405 const OutputDevice *pOutDev ); 406 407 void DrawMask( const SalTwoRect* pPosAry, 408 const SalBitmap& rSalBitmap, 409 SalColor nMaskColor, 410 const OutputDevice *pOutDev ); 411 412 SalBitmap* GetBitmap( long nX, long nY, long nWidth, long nHeight, const OutputDevice *pOutDev ); 413 SalColor GetPixel( long nX, long nY, const OutputDevice *pOutDev ); 414 415 // invert --> ClipRegion (only Windows) 416 void Invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags, const OutputDevice *pOutDev ); 417 void Invert( sal_uLong nPoints, const SalPoint* pPtAry, SalInvert nFlags, const OutputDevice *pOutDev ); 418 419 sal_Bool DrawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, sal_uLong nSize, const OutputDevice *pOutDev ); 420 421 //------------------------------------- 422 // Native Widget Rendering functions 423 //------------------------------------- 424 425 // Query the platform layer for control support 426 virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart ); 427 428 // Query the native control to determine if it was acted upon 429 sal_Bool HitTestNativeControl( ControlType nType, 430 ControlPart nPart, 431 const Rectangle& rControlRegion, 432 const Point& aPos, 433 sal_Bool& rIsInside, 434 const OutputDevice *pOutDev ); 435 436 // Request rendering of a particular control and/or part 437 sal_Bool DrawNativeControl( ControlType nType, 438 ControlPart nPart, 439 const Rectangle& rControlRegion, 440 ControlState nState, 441 const ImplControlValue& aValue, 442 const rtl::OUString& aCaption, 443 const OutputDevice *pOutDev ); 444 445 // Request rendering of a caption string for a control 446 sal_Bool DrawNativeControlText( ControlType nType, 447 ControlPart nPart, 448 const Rectangle& rControlRegion, 449 ControlState nState, 450 const ImplControlValue& aValue, 451 const rtl::OUString& aCaption, 452 const OutputDevice *pOutDev ); 453 454 // Query the native control's actual drawing region (including adornment) 455 sal_Bool GetNativeControlRegion( ControlType nType, 456 ControlPart nPart, 457 const Rectangle& rControlRegion, 458 ControlState nState, 459 const ImplControlValue& aValue, 460 const rtl::OUString& aCaption, 461 Rectangle &rNativeBoundingRegion, 462 Rectangle &rNativeContentRegion, 463 const OutputDevice *pOutDev ); 464 465 static void AddDevFontSubstitute( OutputDevice* pOutDev, 466 const String& rFontName, 467 const String& rReplaceFontName, 468 sal_uInt16 nFlags = 0 ); 469 470 bool DrawAlphaBitmap( const SalTwoRect&, 471 const SalBitmap& rSourceBitmap, 472 const SalBitmap& rAlphaBitmap, 473 const OutputDevice *pOutDev ); 474 475 bool DrawAlphaRect( long nX, long nY, long nWidth, long nHeight, 476 sal_uInt8 nTransparency, const OutputDevice *pOutDev ); 477 478 virtual SystemGraphicsData GetGraphicsData() const = 0; 479 virtual SystemFontData GetSysFontData( int nFallbacklevel ) const = 0; 480 }; 481 482 #endif // _SV_SALGDI_HXX 483