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