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