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_H 29 #define _SV_SALGDI_H 30 31 #include <sallayout.hxx> 32 #include <salgdi.hxx> 33 #include <outfont.hxx> 34 #include <impfont.hxx> 35 36 #include <hash_set> 37 38 class ImplOs2FontEntry; 39 40 // ----------- 41 // - Defines - 42 // ----------- 43 44 // win32 platform specific options. Move them to the PMK file? 45 #define GCP_USEKERNING 0x0008 46 #define USE_UNISCRIBE 47 #define GCP_KERN_HACK 48 #define GNG_VERT_HACK 49 50 // os2 specific physically available font face 51 class ImplOs2FontData : public ImplFontData 52 { 53 public: 54 ImplOs2FontData( PFONTMETRICS, 55 int nFontHeight, 56 PM_BYTE nPitchAndFamily ); 57 ~ImplOs2FontData(); 58 59 virtual ImplFontData* Clone() const; 60 virtual ImplFontEntry* CreateFontInstance( ImplFontSelectData& ) const; 61 virtual sal_IntPtr GetFontId() const; 62 void SetFontId( sal_IntPtr nId ) { mnId = nId; } 63 void UpdateFromHPS( HPS ) const; 64 65 bool HasChar( sal_uInt32 cChar ) const; 66 67 PFONTMETRICS GetFontMetrics() const { return pFontMetric; } 68 USHORT GetCharSet() const { return meOs2CharSet; } 69 PM_BYTE GetPitchAndFamily() const { return mnPitchAndFamily; } 70 bool IsGlyphApiDisabled() const { return mbDisableGlyphApi; } 71 bool SupportsKorean() const { return mbHasKoreanRange; } 72 bool SupportsCJK() const { return mbHasCJKSupport; } 73 bool SupportsArabic() const { return mbHasArabicSupport; } 74 bool AliasSymbolsHigh() const { return mbAliasSymbolsHigh; } 75 bool AliasSymbolsLow() const { return mbAliasSymbolsLow; } 76 77 const ImplFontCharMap* GetImplFontCharMap() const; 78 const Ucs2SIntMap* GetEncodingVector() const { return mpEncodingVector; } 79 void SetEncodingVector( const Ucs2SIntMap* pNewVec ) const 80 { 81 if( mpEncodingVector ) 82 delete mpEncodingVector; 83 mpEncodingVector = pNewVec; 84 } 85 86 private: 87 sal_IntPtr mnId; 88 mutable bool mbDisableGlyphApi; 89 mutable bool mbHasKoreanRange; 90 mutable bool mbHasCJKSupport; 91 92 mutable bool mbHasArabicSupport; 93 mutable ImplFontCharMap* mpUnicodeMap; 94 mutable const Ucs2SIntMap* mpEncodingVector; 95 96 // TODO: get rid of the members below needed to work with the Win9x non-unicode API 97 PM_BYTE* mpFontCharSets; // all Charsets for the current font (used on W98 for kerning) 98 PM_BYTE mnFontCharSetCount; // Number of Charsets of the current font; 0 - if not queried 99 USHORT meOs2CharSet; 100 PM_BYTE mnPitchAndFamily; 101 bool mbAliasSymbolsHigh; 102 bool mbAliasSymbolsLow; 103 PFONTMETRICS pFontMetric; 104 105 private: 106 void ReadCmapTable( HDC ) const; 107 void ReadOs2Table( HDC ) const; 108 109 #ifdef GNG_VERT_HACK 110 void ReadGsubTable( HDC ) const; 111 112 typedef std::hash_set<int> IntHashSet; 113 mutable IntHashSet maGsubTable; 114 mutable bool mbGsubRead; 115 public: 116 bool HasGSUBstitutions( HDC ) const; 117 bool IsGSUBstituted( sal_Unicode ) const; 118 #endif // GNG_VERT_HACK 119 120 }; 121 122 123 // ------------------- 124 // - SalGraphicsData - 125 // ------------------- 126 127 class Os2SalGraphics : public SalGraphics 128 { 129 public: 130 HPS mhPS; // HPS 131 HDC mhDC; // HDC 132 HWND mhWnd; // HWND 133 LONG mnHeight; // Height of frame Window 134 ULONG mnClipElementCount; // number of clip rects in clip rect array 135 RECTL* mpClipRectlAry; // clip rect array 136 ULONG mnFontMetricCount; // number of entries in the font list 137 PFONTMETRICS mpFontMetrics; // cached font list 138 LONG mnOrientationX; // X-Font orientation 139 LONG mnOrientationY; // Y-Font orientation 140 sal_Bool mbLine; // draw lines 141 sal_Bool mbFill; // fill areas 142 sal_Bool mbPrinter; // is Printer 143 sal_Bool mbVirDev; // is VirDev 144 sal_Bool mbWindow; // is Window 145 sal_Bool mbScreen; // is Screen compatible 146 bool mbXORMode; // _every_ output with RasterOp XOR 147 ULONG mhFonts[ MAX_FALLBACK ]; // Font + Fallbacks 148 const ImplOs2FontData* mpOs2FontData[ MAX_FALLBACK ]; // pointer to the most recent font face 149 ImplOs2FontEntry* mpOs2FontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance 150 ULONG mhDefFont; // DefaultFont 151 float mfFontScale; // allows metrics emulation of huge font sizes 152 sal_Bool mbFontKernInit; // FALSE: FontKerns must be queried 153 KERNINGPAIRS* mpFontKernPairs; // Kerning Pairs of the current Font 154 ULONG mnFontKernPairCount;// Number of Kerning Pairs of the current Font 155 156 USHORT ImplDoSetFont( ImplFontSelectData* i_pFont, float& o_rFontScale, int ); 157 158 public: 159 Os2SalGraphics(); 160 virtual ~Os2SalGraphics(); 161 162 protected: 163 virtual bool setClipRegion( const Region& ); 164 // draw --> LineColor and FillColor and RasterOp and ClipRegion 165 virtual void drawPixel( long nX, long nY ); 166 virtual void drawPixel( long nX, long nY, SalColor nSalColor ); 167 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ); 168 virtual void drawRect( long nX, long nY, long nWidth, long nHeight ); 169 virtual void drawPolyLine( ULONG nPoints, const SalPoint* pPtAry ); 170 virtual void drawPolygon( ULONG nPoints, const SalPoint* pPtAry ); 171 virtual void drawPolyPolygon( ULONG nPoly, const ULONG* pPoints, PCONSTSALPOINT* pPtAry ); 172 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ); 173 virtual bool drawPolyLine( const ::basegfx::B2DPolygon&, double fTransparency, const ::basegfx::B2DVector& rLineWidth, basegfx::B2DLineJoin ); 174 virtual sal_Bool drawPolyLineBezier( sal_uIntPtr nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ); 175 virtual sal_Bool drawPolygonBezier( sal_uIntPtr nPoints, const SalPoint* pPtAry, const sal_uInt8* pFlgAry ); 176 virtual sal_Bool drawPolyPolygonBezier( sal_uInt32 nPoly, const sal_uInt32* pPoints, const SalPoint* const* pPtAry, const sal_uInt8* const* pFlgAry ); 177 178 // CopyArea --> No RasterOp, but ClipRegion 179 virtual void copyArea( long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, 180 long nSrcHeight, USHORT nFlags ); 181 182 // CopyBits and DrawBitmap --> RasterOp and ClipRegion 183 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics 184 virtual void copyBits( const SalTwoRect* pPosAry, SalGraphics* pSrcGraphics ); 185 virtual void drawBitmap( const SalTwoRect* pPosAry, const SalBitmap& rSalBitmap ); 186 virtual void drawBitmap( const SalTwoRect* pPosAry, 187 const SalBitmap& rSalBitmap, 188 SalColor nTransparentColor ); 189 virtual void drawBitmap( const SalTwoRect* pPosAry, 190 const SalBitmap& rSalBitmap, 191 const SalBitmap& rTransparentBitmap ); 192 virtual void drawMask( const SalTwoRect* pPosAry, 193 const SalBitmap& rSalBitmap, 194 SalColor nMaskColor ); 195 196 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ); 197 virtual SalColor getPixel( long nX, long nY ); 198 199 // invert --> ClipRegion (only Windows or VirDevs) 200 virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags); 201 virtual void invert( ULONG nPoints, const SalPoint* pPtAry, SalInvert nFlags ); 202 203 virtual sal_Bool drawEPS( long nX, long nY, long nWidth, long nHeight, void* pPtr, ULONG nSize ); 204 205 #if 0 206 // native widget rendering methods that require mirroring 207 virtual sal_Bool hitTestNativeControl( ControlType nType, ControlPart nPart, const Region& rControlRegion, 208 const Point& aPos, sal_Bool& rIsInside ); 209 virtual sal_Bool drawNativeControl( ControlType nType, ControlPart nPart, const Region& rControlRegion, 210 ControlState nState, const ImplControlValue& aValue, 211 rtl::OUString aCaption ); 212 virtual sal_Bool drawNativeControlText( ControlType nType, ControlPart nPart, const Region& rControlRegion, 213 ControlState nState, const ImplControlValue& aValue, 214 rtl::OUString aCaption ); 215 virtual sal_Bool getNativeControlRegion( ControlType nType, ControlPart nPart, const Region& rControlRegion, ControlState nState, 216 const ImplControlValue& aValue, rtl::OUString aCaption, 217 Region &rNativeBoundingRegion, Region &rNativeContentRegion ); 218 #endif 219 220 virtual bool drawAlphaBitmap( const SalTwoRect&, 221 const SalBitmap& rSourceBitmap, 222 const SalBitmap& rAlphaBitmap ); 223 virtual bool drawAlphaRect( long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency ); 224 225 public: 226 // public SalGraphics methods, the interface to teh independent vcl part 227 228 // get device resolution 229 virtual void GetResolution( long& rDPIX, long& rDPIY ); 230 // get the depth of the device 231 virtual USHORT GetBitCount(); 232 // get the width of the device 233 virtual long GetGraphicsWidth() const; 234 235 // set the clip region to empty 236 virtual void ResetClipRegion(); 237 238 // set the line color to transparent (= don't draw lines) 239 virtual void SetLineColor(); 240 // set the line color to a specific color 241 virtual void SetLineColor( SalColor nSalColor ); 242 // set the fill color to transparent (= don't fill) 243 virtual void SetFillColor(); 244 // set the fill color to a specific color, shapes will be 245 // filled accordingly 246 virtual void SetFillColor( SalColor nSalColor ); 247 // enable/disable XOR drawing 248 virtual void SetXORMode( bool bSet, bool ); 249 // set line color for raster operations 250 virtual void SetROPLineColor( SalROPColor nROPColor ); 251 // set fill color for raster operations 252 virtual void SetROPFillColor( SalROPColor nROPColor ); 253 // set the text color to a specific color 254 virtual void SetTextColor( SalColor nSalColor ); 255 // set the font 256 virtual USHORT SetFont( ImplFontSelectData*, int nFallbackLevel ); 257 // get the current font's etrics 258 virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel ); 259 // get kernign pairs of the current font 260 // return only PairCount if (pKernPairs == NULL) 261 virtual ULONG GetKernPairs( ULONG nPairs, ImplKernPairData* pKernPairs ); 262 // get the repertoire of the current font 263 virtual const ImplFontCharMap* GetImplFontCharMap() const; 264 // graphics must fill supplied font list 265 virtual void GetDevFontList( ImplDevFontList* ); 266 // graphics should call ImplAddDevFontSubstitute on supplied 267 // OutputDevice for all its device specific preferred font substitutions 268 virtual void GetDevFontSubstList( OutputDevice* ); 269 virtual bool AddTempDevFont( ImplDevFontList*, const String& rFileURL, const String& rFontName ); 270 // CreateFontSubset: a method to get a subset of glyhps of a font 271 // inside a new valid font file 272 // returns TRUE if creation of subset was successfull 273 // parameters: rToFile: contains a osl file URL to write the subset to 274 // pFont: describes from which font to create a subset 275 // pGlyphIDs: the glyph ids to be extracted 276 // pEncoding: the character code corresponding to each glyph 277 // pWidths: the advance widths of the correspoding glyphs (in PS font units) 278 // nGlyphs: the number of glyphs 279 // rInfo: additional outgoing information 280 // implementation note: encoding 0 with glyph id 0 should be added implicitly 281 // as "undefined character" 282 virtual sal_Bool CreateFontSubset( const rtl::OUString& rToFile, 283 const ImplFontData* pFont, 284 long* pGlyphIDs, 285 sal_uInt8* pEncoding, 286 sal_Int32* pWidths, 287 int nGlyphs, 288 FontSubsetInfo& rInfo // out parameter 289 ); 290 291 // GetFontEncodingVector: a method to get the encoding map Unicode 292 // to font encoded character; this is only used for type1 fonts and 293 // may return NULL in case of unknown encoding vector 294 // if ppNonEncoded is set and non encoded characters (that is type1 295 // glyphs with only a name) exist it is set to the corresponding 296 // map for non encoded glyphs; the encoding vector contains -1 297 // as encoding for these cases 298 virtual const Ucs2SIntMap* GetFontEncodingVector( const ImplFontData*, const Ucs2OStrMap** ppNonEncoded ); 299 300 // GetEmbedFontData: gets the font data for a font marked 301 // embeddable by GetDevFontList or NULL in case of error 302 // parameters: pFont: describes the font in question 303 // pWidths: the widths of all glyphs from char code 0 to 255 304 // pWidths MUST support at least 256 members; 305 // rInfo: additional outgoing information 306 // pDataLen: out parameter, contains the PM_BYTE length of the returned buffer 307 virtual const void* GetEmbedFontData( const ImplFontData*, 308 const sal_Ucs* pUnicodes, 309 sal_Int32* pWidths, 310 FontSubsetInfo& rInfo, 311 long* pDataLen ); 312 // frees the font data again 313 virtual void FreeEmbedFontData( const void* pData, long nDataLen ); 314 315 virtual void GetGlyphWidths( const ImplFontData* pFont, 316 bool bVertical, 317 Int32Vector& rWidths, 318 Ucs2UIntMap& rUnicodeEnc ); 319 320 virtual sal_Bool GetGlyphBoundRect( long nIndex, Rectangle& ); 321 virtual sal_Bool GetGlyphOutline( long nIndex, ::basegfx::B2DPolyPolygon& ); 322 323 virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ); 324 virtual void DrawServerFontLayout( const ServerFontLayout& ); 325 virtual bool supportsOperation( OutDevSupportType ) const; 326 327 // Query the platform layer for control support 328 virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart ); 329 330 virtual SystemGraphicsData GetGraphicsData() const; 331 virtual SystemFontData GetSysFontData( int nFallbacklevel ) const; 332 }; 333 334 // Init/Deinit Graphics 335 void ImplSalInitGraphics( Os2SalGraphics* mpData ); 336 void ImplSalDeInitGraphics( Os2SalGraphics* mpData ); 337 338 // ----------- 339 // - Defines - 340 // ----------- 341 342 #define RGBCOLOR(r,g,b) ((ULONG)(((PM_BYTE)(b)|((USHORT)(g)<<8))|(((ULONG)(PM_BYTE)(r))<<16))) 343 #define TY( y ) (mnHeight-(y)-1) 344 345 // offset for lcid field, used for fallback font selection 346 #define LCID_BASE 100 347 348 // ----------- 349 // - Inlines - 350 // ----------- 351 352 // #102411# Win's GCP mishandles kerning => we need to do it ourselves 353 // SalGraphicsData::mpFontKernPairs is sorted by 354 inline bool ImplCmpKernData( const KERNINGPAIRS& a, const KERNINGPAIRS& b ) 355 { 356 if( a.sFirstChar < b.sFirstChar ) 357 return true; 358 if( a.sFirstChar > b.sFirstChar ) 359 return false; 360 return (a.sSecondChar < b.sSecondChar); 361 } 362 363 // called extremely often from just one spot => inline 364 inline bool ImplOs2FontData::HasChar( sal_uInt32 cChar ) const 365 { 366 if( mpUnicodeMap->HasChar( cChar ) ) 367 return true; 368 // second chance to allow symbol aliasing 369 if( mbAliasSymbolsLow && ((cChar-0xF000) <= 0xFF) ) 370 cChar -= 0xF000; 371 else if( mbAliasSymbolsHigh && (cChar <= 0xFF) ) 372 cChar += 0xF000; 373 return mpUnicodeMap->HasChar( cChar ); 374 } 375 376 #endif // _SV_SALGDI_H 377