1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xlfd_extd.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
36 #include "xlfd_attr.hxx"
37 #include "xlfd_smpl.hxx"
38 #include "xlfd_extd.hxx"
39 #include <vcl/outfont.hxx>
40 #include <rtl/alloc.h>
42 #ifndef _RTL_TENCINFO_H_
43 #include <rtl/tencinfo.h>
48 // --------------------------------------------------------------------------
50 ImplX11FontData::ImplX11FontData( const ExtendedXlfd
& rXlfd
, int nHeight
)
51 : ImplFontData( rXlfd
, X11IFD_MAGIC
),
58 ImplFontEntry
* ImplX11FontData::CreateFontInstance( ImplFontSelectData
& rFSD
) const
60 ImplFontEntry
* pEntry
= new ImplFontEntry( rFSD
);
64 sal_IntPtr
ImplX11FontData::GetFontId() const
66 return reinterpret_cast<sal_IntPtr
>(&mrXlfd
);
69 // --------------------------------------------------------------------------
71 // classes for Xlfd handling that contain more than a single encoding.
72 // Members that may vary through different encodings are stored in
73 // a mpEncodingInfo member. There are three different classes:
74 // true scalable fonts (truetype and type1) scalable bitmap fonts
75 // (the ugly ones) and bitmap fonts. The ExtendedXlfd stores all the members
76 // that are specific to a font outline
77 // ( e.g. adobe-times-roman-medium-r-normal- X -p- X )
78 // and specifies the interface.
80 // --------------------------------------------------------------------------
82 ExtendedXlfd::EncodingInfo
&
83 ExtendedXlfd::EncodingInfo::operator= ( const Xlfd
*pXlfd
)
85 mcSpacing
= pXlfd
->mcSpacing
;
86 mnResolutionX
= pXlfd
->mnResolutionX
;
87 mnResolutionY
= pXlfd
->mnResolutionY
;
88 mnAddstyle
= pXlfd
->mnAddstyle
;
89 mnCharset
= pXlfd
->mnCharset
;
90 mnEncoding
= pXlfd
->GetEncoding();
95 // ------ base class --------------------------------------------------------
97 ExtendedXlfd::ExtendedXlfd( bool bScalable
)
98 : mbScalable( bScalable
),
101 mpEncodingInfo( NULL
)
103 mbOrientation
= false;
105 mbSubsettable
= false;
106 mbEmbeddable
= false;
108 meEmbeddedBitmap
= EMBEDDEDBITMAP_DONTKNOW
;
109 meAntiAlias
= ANTIALIAS_DONTKNOW
;
114 ExtendedXlfd::~ExtendedXlfd()
116 if ( mnEncodings
!= 0 )
117 rtl_freeMemory( mpEncodingInfo
);
121 Realloc( void *pPtr
, sal_Size nSize
)
123 return rtl_reallocateMemory( pPtr
, nSize
);
127 ExtendedXlfd::GetEncodingIdx( rtl_TextEncoding nEncoding
) const
129 for ( int i
= 0; i
< mnEncodings
; i
++ )
130 if ( nEncoding
== mpEncodingInfo
[i
].mnEncoding
)
136 ExtendedXlfd::HasEncoding( rtl_TextEncoding nEncoding
) const
138 return !(GetEncodingIdx( nEncoding
) < 0) ;
142 ExtendedXlfd::GetEncoding( int i
) const
144 if ( i
< mnEncodings
&& i
>= 0 )
145 return mpEncodingInfo
[i
].mnEncoding
;
147 return RTL_TEXTENCODING_DONTKNOW
;
151 ExtendedXlfd::GetEncoding() const
153 return mnEncodings
== 1 ? mpEncodingInfo
[0].mnEncoding
: RTL_TEXTENCODING_DONTKNOW
;
156 // query the most unicode / Ascii compatible font: either one of the fonts
157 // is utf16 encoded or there's a single byte font which is unicode
158 // compatible for the first 256 chars (latin1) or for at least 128
159 // chars (most latin-X encodings, cyrillic encodings)
161 ExtendedXlfd::GetAsciiEncoding( int *pAsciiRange
) const
163 rtl_TextEncoding nBestEncoding
= RTL_TEXTENCODING_DONTKNOW
;
164 int nLargestRange
= 0x0000;
166 for ( int i
= 0; i
< mnEncodings
&& nLargestRange
< 0xffff; i
++ )
168 rtl_TextEncoding nCurEncoding
= mpEncodingInfo
[i
].mnEncoding
;
169 switch ( nCurEncoding
)
171 case RTL_TEXTENCODING_UNICODE
:
172 nLargestRange
= 0xffff;
173 nBestEncoding
= nCurEncoding
;
176 case RTL_TEXTENCODING_ISO_8859_1
:
177 case RTL_TEXTENCODING_MS_1252
:
178 nLargestRange
= 0x00ff;
179 nBestEncoding
= nCurEncoding
;
182 case RTL_TEXTENCODING_ISO_8859_2
:
183 case RTL_TEXTENCODING_ISO_8859_4
:
184 case RTL_TEXTENCODING_ISO_8859_5
:
185 case RTL_TEXTENCODING_ISO_8859_6
:
186 case RTL_TEXTENCODING_ISO_8859_7
:
187 case RTL_TEXTENCODING_ISO_8859_8
:
188 case RTL_TEXTENCODING_ISO_8859_9
:
189 case RTL_TEXTENCODING_ISO_8859_13
:
190 case RTL_TEXTENCODING_ISO_8859_15
:
191 case RTL_TEXTENCODING_MS_1251
:
192 case RTL_TEXTENCODING_KOI8_R
:
193 case RTL_TEXTENCODING_JIS_X_0201
:
194 if ( nLargestRange
< 0x0080 )
196 nLargestRange
= 0x0080;
197 nBestEncoding
= nCurEncoding
;
202 if ( nLargestRange
== 0x0000 )
204 nBestEncoding
= nCurEncoding
;
210 if ( pAsciiRange
!= NULL
)
211 *pAsciiRange
= nLargestRange
;
213 return nBestEncoding
;
217 ExtendedXlfd::AddEncoding( const Xlfd
*pXlfd
)
219 rtl_TextEncoding nEncoding
= pXlfd
->GetEncoding();
220 if ( HasEncoding(nEncoding
) )
223 if ( mnEncodings
== 0 )
226 mnFoundry
= pXlfd
->mnFoundry
;
227 mnFamily
= pXlfd
->mnFamily
;
228 mnWeight
= pXlfd
->mnWeight
;
229 mnSlant
= pXlfd
->mnSlant
;
230 mnSetwidth
= pXlfd
->mnSetwidth
;
231 mpFactory
= pXlfd
->mpFactory
;
233 Attribute
*pFamilyAttr
= mpFactory
->RetrieveFamily( mnFamily
);
234 Attribute
*pWeightAttr
= mpFactory
->RetrieveWeight( mnWeight
);
235 Attribute
*pWidthAttr
= mpFactory
->RetrieveSetwidth( mnSetwidth
);
236 Attribute
*pSlantAttr
= mpFactory
->RetrieveSlant( mnSlant
);
238 meFamily
= GetFamilyType();
239 meWeight
= GetWeight();
240 meItalic
= GetSlant();
241 meWidthType
= GetWidthType();
242 mbSymbolFlag
= (GetEncoding() == RTL_TEXTENCODING_SYMBOL
);
243 mePitch
= GetPitch();
245 maName
= pFamilyAttr
->GetAnnotation();
247 // the helvetica narrow hack
248 if ( ! pFamilyAttr
->HasFeature(XLFD_FEATURE_NARROW
)
249 && pWidthAttr
->HasFeature(XLFD_FEATURE_NARROW
) )
251 static const String
aNarrow( RTL_CONSTASCII_USTRINGPARAM(" Narrow") );
255 // stylename = weight + slant + width
256 // XXX Fix me: there may be a space missing between them
257 if ( meWeight
!= WEIGHT_NORMAL
)
258 maStyleName
+= pWeightAttr
->GetAnnotation();
259 if ( meItalic
!= ITALIC_NONE
)
260 maStyleName
+= pSlantAttr
->GetAnnotation();
261 if ( (meWidthType
!= WIDTH_NORMAL
)
262 && (! pWidthAttr
->HasFeature(XLFD_FEATURE_NARROW
)) )
263 maStyleName
+= pWidthAttr
->GetAnnotation();
266 if( mnEncodings
<= mnEncCapacity
)
268 mnEncCapacity
+= mnEncodings
+ 4;
269 mpEncodingInfo
= (EncodingInfo
*)Realloc( mpEncodingInfo
, mnEncCapacity
* sizeof(EncodingInfo
) );
272 mpEncodingInfo
[ mnEncodings
] = pXlfd
;
278 ExtendedXlfd::ToString( ByteString
&rString
,
279 unsigned short /*nPixelSize*/, rtl_TextEncoding
/*nEncoding*/ ) const
281 AppendAttribute( mpFactory
->RetrieveFoundry(mnFoundry
), rString
);
282 AppendAttribute( mpFactory
->RetrieveFamily(mnFamily
), rString
);
283 AppendAttribute( mpFactory
->RetrieveWeight(mnWeight
), rString
);
284 AppendAttribute( mpFactory
->RetrieveSlant(mnSlant
), rString
);
285 AppendAttribute( mpFactory
->RetrieveSetwidth(mnSetwidth
), rString
);
289 ExtendedXlfd::ToString( ByteString
&rString
,
290 unsigned short /*nPixelSize*/, char* /*pMatricsString*/, rtl_TextEncoding
/*nEncoding*/ ) const
292 AppendAttribute( mpFactory
->RetrieveFoundry(mnFoundry
), rString
);
293 AppendAttribute( mpFactory
->RetrieveFamily(mnFamily
), rString
);
294 AppendAttribute( mpFactory
->RetrieveWeight(mnWeight
), rString
);
295 AppendAttribute( mpFactory
->RetrieveSlant(mnSlant
), rString
);
296 AppendAttribute( mpFactory
->RetrieveSetwidth(mnSetwidth
), rString
);
299 static FontPitch
GetPitchFromX11Pitch( const char cSpacing
)
303 case 'c': // fall through
304 case 'm': return PITCH_FIXED
;
305 case 'p': return PITCH_VARIABLE
;
306 default: return PITCH_DONTKNOW
;
310 // you must not call any of the ExtendedXlfd::GetXXX() functions if the
311 // ExtendedXlfd is really empty (i.e. mnEncodings is zero)
313 FontPitch
ExtendedXlfd::GetPitch() const
315 if( mnEncodings
> 1 )
316 return PITCH_VARIABLE
;
317 if( mnEncodings
== 1 )
318 return GetPitchFromX11Pitch( mpEncodingInfo
[0].mcSpacing
);
319 return PITCH_DONTKNOW
;
322 FontPitch
ExtendedXlfd::GetPitch( rtl_TextEncoding nEncoding
) const
324 for ( int nIdx
= 0; nIdx
< mnEncodings
; nIdx
++ )
325 if ( mpEncodingInfo
[nIdx
].mnEncoding
== nEncoding
)
326 return GetPitchFromX11Pitch( mpEncodingInfo
[nIdx
].mcSpacing
);
327 return PITCH_DONTKNOW
;
330 FontFamily
ExtendedXlfd::GetFamilyType() const
332 Attribute
*pFamilyAttr
= mpFactory
->RetrieveFamily(mnFamily
);
333 return (FontFamily
)pFamilyAttr
->GetValue();
336 FontWeight
ExtendedXlfd::GetWeight() const
338 Attribute
*pWeightAttr
= mpFactory
->RetrieveWeight(mnWeight
);
339 return (FontWeight
)pWeightAttr
->GetValue();
342 FontItalic
ExtendedXlfd::GetSlant() const
344 Attribute
*pSlantAttr
= mpFactory
->RetrieveSlant(mnSlant
);
345 return (FontItalic
)pSlantAttr
->GetValue();
348 FontWidth
ExtendedXlfd::GetWidthType() const
350 Attribute
*pWidthAttr
= mpFactory
->RetrieveSetwidth(mnSetwidth
);
351 return (FontWidth
)pWidthAttr
->GetValue();
357 CodeRange( int nMin
, int nEnd
) : mnMin( nMin
), mnEnd( nEnd
) {}
359 sal_uInt32
GetMin() const { return mnMin
; }
360 sal_uInt32
GetEnd() const { return mnEnd
; }
362 bool operator<( const CodeRange
& r
) const
363 { return (mnMin
<r
.mnMin
) || ((mnMin
==r
.mnMin
) && (mnEnd
<r
.mnEnd
)); }
366 sal_uInt32 mnMin
, mnEnd
;
370 int ExtendedXlfd::GetFontCodeRanges( sal_uInt32
* pCodePairs
) const
372 bool bHasUnicode
= false;
373 bool bHasUnknownEncoding
= false;
375 // approximate unicode ranges from encodings
376 typedef std::set
<CodeRange
> RangeSet
;
379 for( unsigned short i
= 0; i
< mnEncodings
; ++i
)
381 // TODO: move encoding -> unicode range mapping to RTL
382 // NOTE: for now only some are VERY roughly approximated
383 const rtl_TextEncoding eEncoding
= mpEncodingInfo
[i
].mnEncoding
;
384 switch( mpEncodingInfo
[i
].mnEncoding
)
386 case RTL_TEXTENCODING_SYMBOL
: // postscript symbol encoding
387 aRangeSet
.insert( CodeRange( 0x0020, 0x0100 ) ); // symbol aliasing
388 aRangeSet
.insert( CodeRange( 0xF020, 0xF100 ) );
391 case RTL_TEXTENCODING_ISO_8859_15
:
392 aRangeSet
.insert( CodeRange( 0x20AC, 0x20AD ) ); // Euro currency symbol
394 case RTL_TEXTENCODING_APPLE_ROMAN
:
395 case RTL_TEXTENCODING_ISO_8859_1
:
396 case RTL_TEXTENCODING_MS_1252
:
397 case RTL_TEXTENCODING_IBM_437
:
398 case RTL_TEXTENCODING_IBM_852
:
399 aRangeSet
.insert( CodeRange( 0x0020, 0x0080 ) );
400 aRangeSet
.insert( CodeRange( 0x00A0, 0x0100 ) );
403 // Traditional, Simplified, Japanese
404 case RTL_TEXTENCODING_APPLE_CHINSIMP
:
405 case RTL_TEXTENCODING_APPLE_CHINTRAD
:
406 case RTL_TEXTENCODING_APPLE_JAPANESE
:
407 case RTL_TEXTENCODING_SHIFT_JIS
:
408 case RTL_TEXTENCODING_GB_2312
:
409 case RTL_TEXTENCODING_GBT_12345
:
410 case RTL_TEXTENCODING_GBK
:
411 case RTL_TEXTENCODING_BIG5
:
412 case RTL_TEXTENCODING_EUC_JP
:
413 case RTL_TEXTENCODING_EUC_CN
:
414 case RTL_TEXTENCODING_EUC_TW
:
415 case RTL_TEXTENCODING_ISO_2022_JP
:
416 case RTL_TEXTENCODING_ISO_2022_CN
:
417 case RTL_TEXTENCODING_GB_18030
:
418 case RTL_TEXTENCODING_BIG5_HKSCS
:
419 case RTL_TEXTENCODING_JIS_X_0201
:
420 case RTL_TEXTENCODING_JIS_X_0208
:
421 case RTL_TEXTENCODING_JIS_X_0212
:
422 case RTL_TEXTENCODING_MS_932
:
423 case RTL_TEXTENCODING_MS_936
:
424 case RTL_TEXTENCODING_MS_950
:
425 aRangeSet
.insert( CodeRange( 0x3000, 0xA000 ) );
426 aRangeSet
.insert( CodeRange( 0xF900, 0xFB00 ) );
430 case RTL_TEXTENCODING_APPLE_KOREAN
:
431 case RTL_TEXTENCODING_MS_949
:
432 case RTL_TEXTENCODING_MS_1361
:
433 case RTL_TEXTENCODING_EUC_KR
:
434 case RTL_TEXTENCODING_ISO_2022_KR
:
435 aRangeSet
.insert( CodeRange( 0x1100, 0x1200 ) );
436 aRangeSet
.insert( CodeRange( 0x3130, 0x3190 ) );
437 aRangeSet
.insert( CodeRange( 0xAC00, 0xD7A4 ) );
441 case RTL_TEXTENCODING_DONTKNOW
:
442 bHasUnknownEncoding
= true;
446 case RTL_TEXTENCODING_UNICODE
:
447 case RTL_TEXTENCODING_UTF7
:
448 case RTL_TEXTENCODING_UTF8
:
452 // misc 8bit encodings
454 if( !rtl_isOctetTextEncoding( eEncoding
) )
455 bHasUnknownEncoding
= true;
458 // use the unicode converter to get the coverage of an 8bit encoding
459 rtl_TextToUnicodeConverter aConverter
= rtl_createTextToUnicodeConverter( eEncoding
);
460 rtl_UnicodeToTextContext aCvtContext
= rtl_createTextToUnicodeContext( aConverter
);
461 if( !aConverter
|| !aCvtContext
)
462 bHasUnknownEncoding
= true;
465 sal_Char cCharsInp
[ 0x100 ];
466 for( int j
= 0x20; j
< 0x080; ++j
)
467 cCharsInp
[ j
-0x20 ] = j
;
468 for( int j
= 0xA0; j
< 0x100; ++j
)
469 cCharsInp
[ j
-0x40 ] = j
;
471 sal_Unicode cCharsOut
[ 0x100 ];
473 sal_Size nSrcCvtBytes
;
474 int nOutLen
= rtl_convertTextToUnicode(
475 aConverter
, aCvtContext
,
477 cCharsOut
, sizeof(cCharsOut
)/sizeof(*cCharsOut
),
478 RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE
479 | RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE
,
480 &nCvtInfo
, &nSrcCvtBytes
);
482 for( int j
= 0; j
< nOutLen
; ++j
)
483 aRangeSet
.insert( CodeRange( cCharsOut
[j
], cCharsOut
[j
]+1 ) );
485 rtl_destroyTextToUnicodeConverter( aCvtContext
);
486 rtl_destroyTextToUnicodeConverter( aConverter
);
493 // unicode encoded fonts usually do not cover the entire unicode range
494 // => only use them to determine coverage when no other encodings are available
495 if( aRangeSet
.empty() && (bHasUnicode
|| bHasUnknownEncoding
) )
499 pCodePairs
[0] = 0x0020;
500 pCodePairs
[1] = 0xD800;
501 pCodePairs
[2] = 0xE000;
502 pCodePairs
[3] = 0xFFFE;
507 if( aRangeSet
.empty() )
510 // sort and merge the code pairs
511 sal_uInt32
* pDst
= pCodePairs
;
512 RangeSet::const_iterator it
= aRangeSet
.begin();
513 for( sal_uInt32 nEnd
= 0; it
!= aRangeSet
.end(); ++it
)
515 // check overlap with to previous range
516 const CodeRange
& rSrc
= *it
;
517 if( nEnd
< rSrc
.GetMin() )
519 nEnd
= rSrc
.GetEnd();
522 pDst
[0] = rSrc
.GetMin();
523 pDst
[1] = rSrc
.GetEnd();
529 // merge overlapping ranges
530 if( nEnd
< rSrc
.GetEnd() )
532 nEnd
= rSrc
.GetEnd();
539 int nRangeCount
= (pDst
- pCodePairs
) / 2;
543 // ------ class to handle scalable bitmap fonts ------------------------------
545 ScalableBitmapXlfd::ScalableBitmapXlfd()
546 : ExtendedXlfd( true )
549 ScalableBitmapXlfd::~ScalableBitmapXlfd()
553 ScalableBitmapXlfd::ToString( ByteString
&rString
,
554 unsigned short nPixelSize
, rtl_TextEncoding nEncoding
) const
556 int nIdx
= GetEncodingIdx( nEncoding
);
560 ExtendedXlfd::ToString( rString
, nPixelSize
, nEncoding
);
561 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
563 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
566 rString
+= ByteString::CreateFromInt32( nPixelSize
);
568 rString
+= ByteString::CreateFromInt32( rInfo
.mnResolutionX
);
570 rString
+= ByteString::CreateFromInt32( rInfo
.mnResolutionY
);
572 rString
+= static_cast< char >(rInfo
.mcSpacing
);
575 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
579 ScalableBitmapXlfd::ToString( ByteString
&rString
,
580 unsigned short nPixelSize
, char *pMatricsString
, rtl_TextEncoding nEncoding
) const
582 int nIdx
= GetEncodingIdx( nEncoding
);
586 ExtendedXlfd::ToString( rString
, nPixelSize
, nEncoding
);
587 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
589 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
593 snprintf( pTmp
, sizeof(pTmp
), pMatricsString
, nPixelSize
, nPixelSize
);
596 rString
+= static_cast< char >(rInfo
.mcSpacing
);
599 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
602 ImplFontData
* ScalableBitmapXlfd::GetImplFontData() const
604 ImplX11FontData
* pFontData
= new ImplX11FontData( *this, 0 );
605 pFontData
->mnQuality
= 0;
609 // ------ class to handle true bitmap fonts ----------------------------------
612 BitmapXlfd::ToString( ByteString
&rString
,
613 unsigned short nPixelSize
, char *pMatricsString
, rtl_TextEncoding nEncoding
) const
615 int nIdx
= GetEncodingIdx( nEncoding
);
619 ExtendedXlfd::ToString( rString
, nPixelSize
, nEncoding
);
620 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
622 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
626 snprintf( pTmp
, sizeof(pTmp
), pMatricsString
, nPixelSize
, nPixelSize
);
629 rString
+= static_cast< char >(rInfo
.mcSpacing
);
632 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
635 BitmapXlfd::BitmapXlfd( )
636 : ExtendedXlfd( false )
639 BitmapXlfd::~BitmapXlfd( )
643 BitmapXlfd::AddEncoding( const Xlfd
*pXlfd
)
645 if ( mnEncodings
== 0 )
647 mnPixelSize
= pXlfd
->mnPixelSize
;
648 mnPointSize
= pXlfd
->mnPointSize
;
649 mnAverageWidth
= pXlfd
->mnAverageWidth
;
652 return ExtendedXlfd::AddEncoding( pXlfd
);
656 BitmapXlfd::ToString( ByteString
&rString
,
657 unsigned short nPixelSize
, rtl_TextEncoding nEncoding
) const
659 int nIdx
= GetEncodingIdx( nEncoding
);
663 ExtendedXlfd::ToString( rString
, nPixelSize
, nEncoding
);
664 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
665 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
667 rString
+= ByteString::CreateFromInt32( mnPixelSize
);
668 rString
+= "-*-*-*-";
669 rString
+= static_cast< char >(rInfo
.mcSpacing
);
672 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
675 ImplFontData
* BitmapXlfd::GetImplFontData() const
677 ImplX11FontData
* pFontData
= new ImplX11FontData( *this, mnPixelSize
);
678 pFontData
->mnQuality
= 100;
682 // ------ class to handle true scalable fonts --------------------------------
684 ScalableXlfd::ScalableXlfd()
685 : ExtendedXlfd( true )
688 ScalableXlfd::~ScalableXlfd()
692 ScalableXlfd::ToString( ByteString
&rString
,
693 unsigned short nPixelSize
, rtl_TextEncoding nEncoding
) const
695 int nIdx
= GetEncodingIdx( nEncoding
);
699 ExtendedXlfd::ToString( rString
, nPixelSize
, nEncoding
);
701 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
702 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
705 rString
+= ByteString::CreateFromInt32( nPixelSize
);
706 rString
+= "-0-0-0-";
707 rString
+= static_cast< char >(rInfo
.mcSpacing
);
710 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
714 ScalableXlfd::ToString( ByteString
&rString
,
715 unsigned short nPixelSize
, char* pMatricsString
, rtl_TextEncoding nEncoding
) const
717 int nIdx
= GetEncodingIdx( nEncoding
);
721 ExtendedXlfd::ToString( rString
, nPixelSize
, nEncoding
);
723 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
724 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
728 snprintf( pTmp
, sizeof(pTmp
), pMatricsString
, nPixelSize
, nPixelSize
);
731 rString
+= static_cast< char >(rInfo
.mcSpacing
);
734 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
737 ImplFontData
* ScalableXlfd::GetImplFontData() const
739 ImplX11FontData
* pFontData
= new ImplX11FontData( *this, 0 );
740 pFontData
->mnQuality
= 200;
744 /* ------- virtual fonts for user interface ------------------------------- */
746 VirtualXlfd::ExtEncodingInfo
&
747 VirtualXlfd::ExtEncodingInfo::operator= ( const Xlfd
*pXlfd
)
749 mnFoundry
= pXlfd
->mnFoundry
;
750 mnFamily
= pXlfd
->mnFamily
;
751 mnWeight
= pXlfd
->mnWeight
;
752 mnSlant
= pXlfd
->mnSlant
;
753 mnSetwidth
= pXlfd
->mnSetwidth
;
758 VirtualXlfd::VirtualXlfd()
759 : ExtendedXlfd( true ),
761 mpExtEncodingInfo(NULL
)
770 VirtualXlfd::~VirtualXlfd()
772 if ( mpExtEncodingInfo
!= NULL
)
773 rtl_freeMemory( mpExtEncodingInfo
);
777 VirtualXlfd::GetFontQuality (unsigned short nFamily
)
779 Attribute
*pFamily
= mpFactory
->RetrieveFamily(nFamily
);
782 if (pFamily
->HasFeature(XLFD_FEATURE_HQ
))
784 if (pFamily
->HasFeature(XLFD_FEATURE_MQ
))
786 if (pFamily
->HasFeature(XLFD_FEATURE_LQ
))
792 VirtualXlfd::AddEncoding( const Xlfd
*pXlfd
)
795 bool bRC
= ExtendedXlfd::AddEncoding( pXlfd
);
800 // new encoding => append the new pXlfd
801 nIdx
= mnEncodings
- 1;
802 if( nIdx
>= mnExtCapacity
)
804 mnExtCapacity
= mnEncCapacity
;
805 mpExtEncodingInfo
= (ExtEncodingInfo
*)Realloc( mpExtEncodingInfo
,
806 mnExtCapacity
* sizeof(ExtEncodingInfo
) );
811 // existing encoding => check if the new pXlfd is better
812 rtl_TextEncoding nEncoding
= pXlfd
->GetEncoding();
813 nIdx
= GetEncodingIdx( nEncoding
);
815 int nOldQuality
= GetFontQuality( mpExtEncodingInfo
[nIdx
].mnFamily
);
816 int nNewQuality
= GetFontQuality( pXlfd
->mnFamily
);
817 if( nOldQuality
>= nNewQuality
)
821 mpExtEncodingInfo
[ nIdx
] = pXlfd
;
826 VirtualXlfd::FilterInterfaceFont (const Xlfd
*pXlfd
)
829 AttributeProvider
*pFactory
= pXlfd
->mpFactory
;
831 if (! pXlfd
->Fonttype() == TYPE_SCALABLE
)
833 pAttr
= pFactory
->RetrieveFamily(pXlfd
->mnFamily
);
834 if (! pAttr
->HasFeature(XLFD_FEATURE_INTERFACE_FONT
))
836 pAttr
= pFactory
->RetrieveSlant(pXlfd
->mnSlant
);
837 if (! (FontItalic
)pAttr
->GetValue() == ITALIC_NONE
)
839 pAttr
= pFactory
->RetrieveSetwidth(pXlfd
->mnSetwidth
);
840 if (pAttr
->HasFeature(XLFD_FEATURE_NARROW
))
842 pAttr
= pFactory
->RetrieveWeight(pXlfd
->mnWeight
);
843 FontWeight eWeight
= (FontWeight
)pAttr
->GetValue();
844 if ((eWeight
!= WEIGHT_NORMAL
) && (eWeight
!= WEIGHT_MEDIUM
))
851 VirtualXlfd::ToString( ByteString
&rString
, unsigned short nPixelSize
,
852 rtl_TextEncoding nEncoding
) const
854 int nIdx
= GetEncodingIdx( nEncoding
);
858 ExtEncodingInfo
&rExtInfo
= mpExtEncodingInfo
[ nIdx
];
860 AppendAttribute( mpFactory
->RetrieveFoundry(rExtInfo
.mnFoundry
), rString
);
861 AppendAttribute( mpFactory
->RetrieveFamily(rExtInfo
.mnFamily
), rString
);
862 AppendAttribute( mpFactory
->RetrieveWeight(rExtInfo
.mnWeight
), rString
);
863 AppendAttribute( mpFactory
->RetrieveSlant(rExtInfo
.mnSlant
), rString
);
864 AppendAttribute( mpFactory
->RetrieveSetwidth(rExtInfo
.mnSetwidth
), rString
);
866 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
867 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
870 rString
+= ByteString::CreateFromInt32( nPixelSize
);
871 rString
+= "-0-0-0-";
872 rString
+= static_cast< char >(rInfo
.mcSpacing
);
875 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
879 VirtualXlfd::ToString( ByteString
&rString
, unsigned short nPixelSize
,
880 char* pMatricsString
, rtl_TextEncoding nEncoding
) const
882 int nIdx
= GetEncodingIdx( nEncoding
);
886 ExtEncodingInfo
&rExtInfo
= mpExtEncodingInfo
[ nIdx
];
888 AppendAttribute( mpFactory
->RetrieveFoundry(rExtInfo
.mnFoundry
), rString
);
889 AppendAttribute( mpFactory
->RetrieveFamily(rExtInfo
.mnFamily
), rString
);
890 AppendAttribute( mpFactory
->RetrieveWeight(rExtInfo
.mnWeight
), rString
);
891 AppendAttribute( mpFactory
->RetrieveSlant(rExtInfo
.mnSlant
), rString
);
892 AppendAttribute( mpFactory
->RetrieveSetwidth(rExtInfo
.mnSetwidth
), rString
);
894 EncodingInfo
& rInfo
= mpEncodingInfo
[ nIdx
];
895 AppendAttribute( mpFactory
->RetrieveAddstyle(rInfo
.mnAddstyle
), rString
);
899 snprintf( pTmp
, sizeof(pTmp
), pMatricsString
, nPixelSize
, nPixelSize
);
902 rString
+= static_cast< char >(rInfo
.mcSpacing
);
905 AppendAttribute( mpFactory
->RetrieveCharset(rInfo
.mnCharset
), rString
);
908 ImplFontData
* VirtualXlfd::GetImplFontData() const
910 ImplX11FontData
* pFontData
= new ImplX11FontData( *this, 0 );
913 static const String
aFontName( RTL_CONSTASCII_USTRINGPARAM("Interface User") );
914 pFontData
->maName
= aFontName
;
915 // pFontData->maStyleName = aStyleName;
916 pFontData
->meFamily
= FAMILY_SWISS
;
917 pFontData
->meWeight
= WEIGHT_NORMAL
;
918 pFontData
->meItalic
= ITALIC_NONE
;
919 pFontData
->meWidthType
= WIDTH_NORMAL
;
920 pFontData
->mePitch
= PITCH_VARIABLE
;
922 pFontData
->mbSymbolFlag
= false;
923 pFontData
->mbOrientation
= false;
924 pFontData
->mbDevice
= true;
925 pFontData
->mnQuality
= 100;
930 // ------ font list -------------------------------------------------------
932 XlfdStorage::XlfdStorage()
934 maXlfdList
.reserve( 256 );
938 XlfdStorage::Dispose()
940 XlfdList::const_iterator it
= maXlfdList
.begin();
941 for(; it
!= maXlfdList
.end(); ++it
)
953 XlfdStorage::Add( const ExtendedXlfd
* pXlfd
)
956 maXlfdList
.push_back( pXlfd
);
960 XlfdStorage::Add( const XlfdStorage
* pXlfd
)
962 if ( !pXlfd
|| pXlfd
->maXlfdList
.empty() )
965 maXlfdList
.reserve( maXlfdList
.size() + pXlfd
->maXlfdList
.size() );
966 XlfdList::const_iterator it
= pXlfd
->maXlfdList
.begin();
967 for(; it
!= pXlfd
->maXlfdList
.end(); ++it
)
968 maXlfdList
.push_back( *it
);
971 void XlfdStorage::AnnounceFonts( ImplDevFontList
* pList
) const
973 XlfdList::const_iterator it
= maXlfdList
.begin();
974 for(; it
!= maXlfdList
.end(); ++it
)
976 const ExtendedXlfd
* pXlfd
= *it
;
977 ImplFontData
* pFontData
= pXlfd
->GetImplFontData();
978 pList
->Add( pFontData
);
982 // ------ bitmap font list --------------------------------------------------
985 BitmapXlfdStorage::AddBitmapFont( const Xlfd
*pXlfd
)
990 int nPixelSize
= pXlfd
->mnPixelSize
;
991 XlfdList::const_iterator it
= maXlfdList
.begin();
992 for(; it
!= maXlfdList
.end(); ++it
)
994 BitmapXlfd
* pBitmapXlfd
= (BitmapXlfd
*)*it
;
995 if( nPixelSize
== pBitmapXlfd
->GetPixelSize() )
997 // we need to add an encoding to an existing bitmap font
998 pBitmapXlfd
->AddEncoding( pXlfd
);
1003 // we have a new bitmap font
1004 BitmapXlfd
* pBitmapXlfd
= new BitmapXlfd
;
1005 pBitmapXlfd
->AddEncoding( pXlfd
);