From 488f685350a8389f1f21400d887fedcb20b64cc0 Mon Sep 17 00:00:00 2001 From: Christof Pintaske Date: Mon, 19 Mar 2001 07:31:46 +0000 Subject: x11 font cleanup --- vcl/unx/source/app/saldisp.cxx | 13 +- vcl/unx/source/gdi/salcvt.cxx | 148 +++---------- vcl/unx/source/gdi/salcvt.hxx | 16 +- vcl/unx/source/gdi/salgdi3.cxx | 435 +++++++++++++++------------------------ vcl/unx/source/gdi/xfont.cxx | 161 ++++++--------- vcl/unx/source/gdi/xlfd_attr.cxx | 54 +++-- vcl/unx/source/gdi/xlfd_attr.hxx | 21 +- vcl/unx/source/gdi/xlfd_extd.cxx | 45 +++- vcl/unx/source/gdi/xlfd_extd.hxx | 13 +- 9 files changed, 368 insertions(+), 538 deletions(-) (limited to 'vcl/unx/source') diff --git a/vcl/unx/source/app/saldisp.cxx b/vcl/unx/source/app/saldisp.cxx index 2b0ee616aa35..8665799b39c0 100644 --- a/vcl/unx/source/app/saldisp.cxx +++ b/vcl/unx/source/app/saldisp.cxx @@ -2,9 +2,9 @@ * * $RCSfile: saldisp.cxx,v $ * - * $Revision: 1.16 $ + * $Revision: 1.17 $ * - * last change: $Author: pl $ $Date: 2001-03-02 14:23:27 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:30:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -678,7 +678,8 @@ BOOL SalDisplay::BestVisual( Display *pDisplay, // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -SalDisplay::SalDisplay( Widget w ) +SalDisplay::SalDisplay( Widget w ) : + mpFallbackFactory ( NULL ) { SalData *pSalData = GetSalData(); @@ -718,8 +719,9 @@ SalDisplay::SalDisplay( Widget w ) Init( hColMap, &aXVI ); } -SalDisplay::SalDisplay( Display *display, Visual *pVisual, - Colormap aColMap ) : pDisp_( display ) +SalDisplay::SalDisplay( Display *display, Visual *pVisual, Colormap aColMap ) : + pDisp_( display ), + mpFallbackFactory ( NULL ) { SalData *pSalData = GetSalData(); XVisualInfo aXVI; @@ -861,7 +863,6 @@ void SalDisplay::Init( Colormap hXColmap, const XVisualInfo* pXVI ) pFontCache_ = NULL; mpFontList = (XlfdStorage*)NULL; mpFactory = (AttributeProvider*)NULL; - mpCvtCache = NULL; pCapture_ = NULL; pVisual_ = new SalVisual( pXVI ); aSize_ = Size( DisplayWidth ( pDisp_, nScreen_ ), diff --git a/vcl/unx/source/gdi/salcvt.cxx b/vcl/unx/source/gdi/salcvt.cxx index 517157a6df48..55258eef249e 100644 --- a/vcl/unx/source/gdi/salcvt.cxx +++ b/vcl/unx/source/gdi/salcvt.cxx @@ -2,9 +2,9 @@ * * $RCSfile: salcvt.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: cp $ $Date: 2000-12-19 11:21:45 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,6 +68,16 @@ SalConverterCache::SalConverterCache() mpConverter = (ConverterT*)calloc( sizeof(ConverterT), RTL_TEXTENCODING_STD_COUNT ); } +SalConverterCache* +SalConverterCache::GetInstance () +{ + static SalConverterCache* pCvt = NULL; + if (pCvt == NULL) + pCvt = new SalConverterCache; + + return pCvt; +} + SalConverterCache::~SalConverterCache() { for ( int i = 0; i < RTL_TEXTENCODING_STD_COUNT; i++ ) @@ -95,8 +105,7 @@ SalConverterCache::GetU2TConverter( rtl_TextEncoding nEncoding ) rtl_createUnicodeToTextConverter( nEncoding ); // ---> FIXME if ( mpConverter[ nEncoding ].mpU2T == NULL ) - fprintf( stderr, "failed to create Unicode -> %s converter\n", - pGetEncodingName(nEncoding) ); + fprintf( stderr, "failed to create Unicode -> %i converter\n", nEncoding); // <--- } return mpConverter[ nEncoding ].mpU2T; @@ -115,8 +124,7 @@ SalConverterCache::GetT2UConverter( rtl_TextEncoding nEncoding ) rtl_createTextToUnicodeConverter( nEncoding ); // ---> FIXME if ( mpConverter[ nEncoding ].mpT2U == NULL ) - fprintf( stderr, "failed to create %s -> Unicode converter\n", - pGetEncodingName(nEncoding) ); + fprintf( stderr, "failed to create %i -> Unicode converter\n", nEncoding ); // <--- } return mpConverter[ nEncoding ].mpT2U; @@ -314,10 +322,11 @@ SalConverterCache::EncodingHasChar( rtl_TextEncoding nEncoding, // wrapper for rtl_convertUnicodeToText that handles the usual cases for // textconversion in drawtext and gettextwidth routines sal_Size -ConvertStringUTF16( const sal_Unicode *pText, int nTextLen, - sal_Char *pBuffer, sal_Size nBufferSize, - rtl_UnicodeToTextConverter aConverter ) +SalConverterCache::ConvertStringUTF16( const sal_Unicode *pText, int nTextLen, + sal_Char *pBuffer, sal_Size nBufferSize, rtl_TextEncoding nEncoding ) { + rtl_UnicodeToTextConverter aConverter = GetU2TConverter(nEncoding); + const sal_uInt32 nCvtFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK | RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK ; @@ -333,119 +342,14 @@ ConvertStringUTF16( const sal_Unicode *pText, int nTextLen, rtl_destroyUnicodeToTextContext( aConverter, aContext ); - return nSize; -} - -typedef struct { - const rtl_TextEncoding nEncoding; - const char* pEncoding; -} DescriptionT; - -const DescriptionT pRTLEncoding[] = { - { RTL_TEXTENCODING_DONTKNOW, "DONTKNOW" }, - { RTL_TEXTENCODING_MS_1252, "MS_1252" }, - { RTL_TEXTENCODING_APPLE_ROMAN, "APPLE_ROMAN" }, - { RTL_TEXTENCODING_IBM_437, "IBM_437" }, - { RTL_TEXTENCODING_IBM_850, "IBM_850" }, - { RTL_TEXTENCODING_IBM_860, "IBM_860" }, - { RTL_TEXTENCODING_IBM_861, "IBM_861" }, - { RTL_TEXTENCODING_IBM_863, "IBM_863" }, - { RTL_TEXTENCODING_IBM_865, "IBM_865" }, - { RTL_TEXTENCODING_SYMBOL, "SYMBOL" }, - { RTL_TEXTENCODING_ASCII_US, "ASCII_US" }, - { RTL_TEXTENCODING_ISO_8859_1, "ISO_8859_1" }, - { RTL_TEXTENCODING_ISO_8859_2, "ISO_8859_2" }, - { RTL_TEXTENCODING_ISO_8859_3, "ISO_8859_3" }, - { RTL_TEXTENCODING_ISO_8859_4, "ISO_8859_4" }, - { RTL_TEXTENCODING_ISO_8859_5, "ISO_8859_5" }, - { RTL_TEXTENCODING_ISO_8859_6, "ISO_8859_6" }, - { RTL_TEXTENCODING_ISO_8859_7, "ISO_8859_7" }, - { RTL_TEXTENCODING_ISO_8859_8, "ISO_8859_8" }, - { RTL_TEXTENCODING_ISO_8859_9, "ISO_8859_9" }, - { RTL_TEXTENCODING_ISO_8859_14, "ISO_8859_14" }, - { RTL_TEXTENCODING_ISO_8859_15, "ISO_8859_15" }, - { RTL_TEXTENCODING_IBM_737, "IBM_737" }, - { RTL_TEXTENCODING_IBM_775, "IBM_775" }, - { RTL_TEXTENCODING_IBM_852, "IBM_852" }, - { RTL_TEXTENCODING_IBM_855, "IBM_855" }, - { RTL_TEXTENCODING_IBM_857, "IBM_857" }, - { RTL_TEXTENCODING_IBM_862, "IBM_862" }, - { RTL_TEXTENCODING_IBM_864, "IBM_864" }, - { RTL_TEXTENCODING_IBM_866, "IBM_866" }, - { RTL_TEXTENCODING_IBM_869, "IBM_869" }, - { RTL_TEXTENCODING_MS_874, "MS_874" }, - { RTL_TEXTENCODING_MS_1250, "MS_1250" }, - { RTL_TEXTENCODING_MS_1251, "MS_1251" }, - { RTL_TEXTENCODING_MS_1253, "MS_1253" }, - { RTL_TEXTENCODING_MS_1254, "MS_1254" }, - { RTL_TEXTENCODING_MS_1255, "MS_1255" }, - { RTL_TEXTENCODING_MS_1256, "MS_1256" }, - { RTL_TEXTENCODING_MS_1257, "MS_1257" }, - { RTL_TEXTENCODING_MS_1258, "MS_1258" }, - { RTL_TEXTENCODING_APPLE_ARABIC, "APPLE_ARABIC" }, - { RTL_TEXTENCODING_APPLE_CENTEURO, "APPLE_CENTEURO" }, - { RTL_TEXTENCODING_APPLE_CROATIAN, "APPLE_CROATIAN" }, - { RTL_TEXTENCODING_APPLE_CYRILLIC, "APPLE_CYRILLIC" }, - { RTL_TEXTENCODING_APPLE_DEVANAGARI,"APPLE_DEVANAGARI" }, - { RTL_TEXTENCODING_APPLE_FARSI, "APPLE_FARSI" }, - { RTL_TEXTENCODING_APPLE_GREEK, "APPLE_GREEK" }, - { RTL_TEXTENCODING_APPLE_GUJARATI, "APPLE_GUJARATI" }, - { RTL_TEXTENCODING_APPLE_GURMUKHI, "APPLE_GURMUKHI" }, - { RTL_TEXTENCODING_APPLE_HEBREW, "APPLE_HEBREW" }, - { RTL_TEXTENCODING_APPLE_ICELAND, "APPLE_ICELAND" }, - { RTL_TEXTENCODING_APPLE_ROMANIAN, "APPLE_ROMANIAN" }, - { RTL_TEXTENCODING_APPLE_THAI, "APPLE_THAI" }, - { RTL_TEXTENCODING_APPLE_TURKISH, "APPLE_TURKISH" }, - { RTL_TEXTENCODING_APPLE_UKRAINIAN, "APPLE_UKRAINIAN" }, - { RTL_TEXTENCODING_APPLE_CHINSIMP, "APPLE_CHINSIMP" }, - { RTL_TEXTENCODING_APPLE_CHINTRAD, "APPLE_CHINTRAD" }, - { RTL_TEXTENCODING_APPLE_JAPANESE, "APPLE_JAPANESE" }, - { RTL_TEXTENCODING_APPLE_KOREAN, "APPLE_KOREAN" }, - { RTL_TEXTENCODING_MS_932, "MS_932" }, - { RTL_TEXTENCODING_MS_936, "MS_936" }, - { RTL_TEXTENCODING_MS_949, "MS_949" }, - { RTL_TEXTENCODING_MS_950, "MS_950" }, - { RTL_TEXTENCODING_SHIFT_JIS, "SHIFT_JIS" }, - { RTL_TEXTENCODING_GB_2312, "GB_2312" }, - { RTL_TEXTENCODING_GBT_12345, "GBT_12345" }, - { RTL_TEXTENCODING_GBK, "GBK" }, - { RTL_TEXTENCODING_BIG5, "BIG5" }, - { RTL_TEXTENCODING_EUC_JP, "EUC_JP" }, - { RTL_TEXTENCODING_EUC_CN, "EUC_CN" }, - { RTL_TEXTENCODING_EUC_TW, "EUC_TW" }, - { RTL_TEXTENCODING_ISO_2022_JP, "ISO_2022_JP" }, - { RTL_TEXTENCODING_ISO_2022_CN, "ISO_2022_CN" }, - { RTL_TEXTENCODING_KOI8_R, "KOI8_R" }, - { RTL_TEXTENCODING_UTF7, "UTF7" }, - { RTL_TEXTENCODING_UTF8, "UTF8" }, - { RTL_TEXTENCODING_ISO_8859_10, "ISO_8859_10" }, - { RTL_TEXTENCODING_ISO_8859_13, "ISO_8859_13" }, - { RTL_TEXTENCODING_EUC_KR, "EUC_KR" }, - { RTL_TEXTENCODING_ISO_2022_KR, "ISO_2022_KR" }, - { RTL_TEXTENCODING_JIS_X_0208, "JISX_0208_1983" }, - { RTL_TEXTENCODING_JIS_X_0201, "JISX_0201_1976" }, - { RTL_TEXTENCODING_JIS_X_0212, "JISX_0212_1990" }, - #ifdef __notdef__ - { RTL_TEXTENCODING_KSC_5601_1992, "KSC_5601_1992" }, - { RTL_TEXTENCODING_TIS_620_2533, "TIS_620_2533" }, - { RTL_TEXTENCODING_SUNUDC_1997, "SUNUDC_1997" }, - #endif - { RTL_TEXTENCODING_STD_COUNT, "STD_COUNT" }, - { RTL_TEXTENCODING_USER_START, "USER_START" }, - { RTL_TEXTENCODING_USER_END, "USER_END" }, - { RTL_TEXTENCODING_UCS4, "UCS4" }, - { RTL_TEXTENCODING_UCS2, "UCS2" }, - { RTL_TEXTENCODING_UNICODE, "UNICODE" } -}; - -extern "C" const char* -pGetEncodingName( rtl_TextEncoding nEncoding ) -{ - for ( int i = 0; i < sizeof(pRTLEncoding)/sizeof(DescriptionT); i++ ) - if ( nEncoding == pRTLEncoding[i].nEncoding ) - return pRTLEncoding[i].pEncoding; + // XXX FIXME + if ( (nEncoding == RTL_TEXTENCODING_GB_2312) + || (nEncoding == RTL_TEXTENCODING_EUC_KR) ) + { + for (int n_char = 0; n_char < nSize; n_char++ ) + pBuffer[ n_char ] &= 0x7F; + } - static const char p_nil[] = "not_in_list"; - return p_nil; + return nSize; } diff --git a/vcl/unx/source/gdi/salcvt.hxx b/vcl/unx/source/gdi/salcvt.hxx index 540f879af9d5..33a4e723fac8 100644 --- a/vcl/unx/source/gdi/salcvt.hxx +++ b/vcl/unx/source/gdi/salcvt.hxx @@ -2,9 +2,9 @@ * * $RCSfile: salcvt.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 17:05:43 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -91,6 +91,12 @@ class SalConverterCache { rtl_TextToUnicodeConverter GetT2UConverter( rtl_TextEncoding nEncoding ); Bool IsSingleByteEncoding( rtl_TextEncoding nEncoding ); + sal_Size ConvertStringUTF16( const sal_Unicode *pText, int nTextLen, + sal_Char *pBuffer, sal_Size nBufferSize, + rtl_TextEncoding nEncoding); + + static SalConverterCache* + GetInstance (); private: @@ -104,12 +110,6 @@ class SalConverterCache { ConverterT *mpConverter; }; -// wrapper for rtl_convertUnicodeToText that handles the usual cases for -// textconversion in drawtext routines -sal_Size -ConvertStringUTF16( const sal_Unicode *pText, int nTextLen, - sal_Char *pBuffer, sal_Size nBufferSize, - rtl_UnicodeToTextConverter aConverter ); #endif /* SAL_CONVERTER_CACHE_HXX_ */ diff --git a/vcl/unx/source/gdi/salgdi3.cxx b/vcl/unx/source/gdi/salgdi3.cxx index 065bee515d46..701925daf3aa 100644 --- a/vcl/unx/source/gdi/salgdi3.cxx +++ b/vcl/unx/source/gdi/salgdi3.cxx @@ -2,9 +2,9 @@ * * $RCSfile: salgdi3.cxx,v $ * - * $Revision: 1.29 $ + * $Revision: 1.30 $ * - * last change: $Author: cp $ $Date: 2001-03-15 14:24:15 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -83,8 +83,8 @@ #ifndef _SV_SALGDI_HXX #include #endif -#ifndef _SV_OUTFONT_HXX -#include +#ifndef _SV_OUTDEV_H +#include #endif #ifndef _STRING_HXX #include @@ -350,6 +350,7 @@ SalDisplay::GetXlfdList() // create a font set for user interface mpFontList->InterfaceFont( mpFactory ); + mpFallbackFactory = mpFontList->GetInterfaceFont (); // cleanup the list of simple font information if ( pXlfdList != NULL ) @@ -362,11 +363,10 @@ SalDisplay::GetXlfdList() // --------------------------------------------------------------------------- ExtendedFontStruct* -SalDisplay::GetFont( ExtendedXlfd *pRequestedFont, int nPixelSize ) +SalDisplay::GetFont( const ExtendedXlfd *pRequestedFont, int nPixelSize, sal_Bool bVertical ) { if( !pFontCache_ ) { - mpCvtCache = new SalConverterCache; pFontCache_ = new SalFontCache( 64, 64, 16 ); // ??? } else @@ -376,7 +376,7 @@ SalDisplay::GetFont( ExtendedXlfd *pRequestedFont, int nPixelSize ) pItem != NULL; pItem = pFontCache_->Next() ) { - if ( pItem->Match(pRequestedFont, nPixelSize) ) + if ( pItem->Match(pRequestedFont, nPixelSize, bVertical) ) { if( pFontCache_->GetCurPos() ) { @@ -405,11 +405,11 @@ SalDisplay::GetFont( ExtendedXlfd *pRequestedFont, int nPixelSize ) break; } } - } ExtendedFontStruct *pItem = new ExtendedFontStruct( GetDisplay(), - nPixelSize, pRequestedFont, mpCvtCache ); + nPixelSize, bVertical, + const_cast(pRequestedFont) ); pFontCache_->Insert( pItem, 0UL ); pItem->AddRef(); @@ -440,15 +440,10 @@ SalDisplay::DestroyFontCache() { delete mpFactory; } - if ( mpCvtCache ) - { - delete mpCvtCache; - } pFontCache_ = (SalFontCache*)NULL; mpFontList = (XlfdStorage*)NULL; mpFactory = (AttributeProvider*)NULL; - mpCvtCache = (SalConverterCache*)NULL; } // ---------------------------------------------------------------------------- @@ -521,11 +516,12 @@ GetMaxFontHeight() void SalGraphicsData::SetFont( const ImplFontSelectData *pEntry ) { - bFontGC_ = FALSE; - xFont_ = NULL; // ->ReleaseRef() - aScale_ = Fraction( 1, 1 ); - nFontOrientation_ = pEntry->mnOrientation; - bFontVertical_ = pEntry->mbVertical; + bFontGC_ = FALSE; + xFont_ = NULL; // ->ReleaseRef() + mxFallbackFont = NULL; + aScale_ = Fraction( 1, 1 ); + nFontOrientation_ = pEntry->mnOrientation; + bFontVertical_ = pEntry->mbVertical; #ifdef USE_BUILTIN_RASTERIZER if( mpServerSideFont != NULL ) @@ -566,18 +562,16 @@ SalGraphicsData::SetFont( const ImplFontSelectData *pEntry ) nW = pEntry->mnWidth; } - xFont_ = GetDisplay()->GetFont( pSysFont, nH ); + xFont_ = GetDisplay()->GetFont( pSysFont, nH, bFontVertical_ ); + const ExtendedXlfd *pFactory = GetDisplay()->GetFallbackFactory(); + if ( pFactory != NULL) + mxFallbackFont = GetDisplay()->GetFont(pFactory, nH, bFontVertical_); if( pEntry->mnHeight > nMaxFontHeight || pEntry->mnHeight < 2 ) aScale_ = Fraction( pEntry->mnHeight, nH ); } else { -#ifdef DEBUG - // XXX Fix me: provide a fallback for poor font installations - // we may be reach this if no font matches the GUI font - // MS Sans Serif;Geneva;Helv;WarpSans;Dialog;Lucida; ... */ - fprintf( stderr, "SalGraphicsData::SetFont: Invalid Font Selection\n" ); -#endif + xFont_ = mxFallbackFont; } } @@ -589,133 +583,71 @@ SwapBytes( const sal_Unicode nIn ) return ((nIn >> 8) & 0x00ff) | ((nIn << 8) & 0xff00); } - // draw string in a specific multibyte encoding static void -ConvertTextItem16( XTextItem16* pTextItem, - SalConverterCache* pCvt, rtl_TextEncoding nEncoding ) +ConvertTextItem16( XTextItem16* pTextItem, rtl_TextEncoding nEncoding ) { - if ( pTextItem && pTextItem->nchars > 0 ) - { - // convert the string into the font encoding - sal_Size nSize; - sal_Size nBufferSize = pTextItem->nchars * 2; - sal_Char *pBuffer = (sal_Char*)alloca( nBufferSize ); + if ( (pTextItem == NULL) || (pTextItem->nchars <= 0) ) + return; - nSize = ConvertStringUTF16( (sal_Unicode*)pTextItem->chars, pTextItem->nchars, - pBuffer, nBufferSize, pCvt->GetU2TConverter(nEncoding)); + SalConverterCache* pCvt = SalConverterCache::GetInstance(); + // convert the string into the font encoding + sal_Size nSize; + sal_Size nBufferSize = pTextItem->nchars * 2; + sal_Char *pBuffer = (sal_Char*)alloca( nBufferSize ); - sal_Char *pTextChars = (sal_Char*)pTextItem->chars; - int n = 0, m = 0; + nSize = pCvt->ConvertStringUTF16( (sal_Unicode*)pTextItem->chars, pTextItem->nchars, + pBuffer, nBufferSize, nEncoding); - if ( nEncoding == RTL_TEXTENCODING_GB_2312 - || nEncoding == RTL_TEXTENCODING_GBT_12345 - || nEncoding == RTL_TEXTENCODING_GBK - || nEncoding == RTL_TEXTENCODING_BIG5 ) - { - // GB and Big5 needs special treatment since chars can be single or - // double byte: encoding is - // [ 0x00 - 0x7f ] | [ 0x81 - 0xfe ] [ 0x40 - 0x7e 0x80 - 0xfe ] - while ( n < nSize ) - { - if ( (unsigned char)pBuffer[ n ] < 0x80 ) - { - pTextChars[ m++ ] = 0x0; - pTextChars[ m++ ] = pBuffer[ n++ ]; - } - else - { - pTextChars[ m++ ] = pBuffer[ n++ ]; - pTextChars[ m++ ] = pBuffer[ n++ ]; - } - } - pTextItem->nchars = m / 2; - } - else - if ( pCvt->IsSingleByteEncoding(nEncoding) ) + sal_Char *pTextChars = (sal_Char*)pTextItem->chars; + int n = 0, m = 0; + + if ( nEncoding == RTL_TEXTENCODING_GB_2312 + || nEncoding == RTL_TEXTENCODING_GBT_12345 + || nEncoding == RTL_TEXTENCODING_GBK + || nEncoding == RTL_TEXTENCODING_BIG5 ) + { + // GB and Big5 needs special treatment since chars can be single or + // double byte: encoding is + // [ 0x00 - 0x7f ] | [ 0x81 - 0xfe ] [ 0x40 - 0x7e 0x80 - 0xfe ] + while ( n < nSize ) { - // Single Byte encoding has to be padded - while ( n < nSize ) + if ( (unsigned char)pBuffer[ n ] < 0x80 ) { pTextChars[ m++ ] = 0x0; pTextChars[ m++ ] = pBuffer[ n++ ]; } - pTextItem->nchars = nSize; - } - else - { - while ( n < nSize ) + else { pTextChars[ m++ ] = pBuffer[ n++ ]; + pTextChars[ m++ ] = pBuffer[ n++ ]; } - pTextItem->nchars = nSize / 2; - } - - // XXX FIXME - if ( (nEncoding == RTL_TEXTENCODING_GB_2312) - || (nEncoding == RTL_TEXTENCODING_EUC_KR) ) - { - for (int n_char = 0; n_char < m; n_char++ ) - pTextChars[ n_char ] &= 0x7F; } - + pTextItem->nchars = m / 2; } -} - -// XXX this is a hack since XPrinter is not multibyte capable -// XXX for printing this routine is called for each character -void -XPrinterDrawText16( Display* pDisplay, Drawable nDrawable, GC nGC, - int nX, int nY, int nAngle, XTextItem16 *pTextItem16, int nItem ) -{ - // convert XTextItem16 to XTextItem - XTextItem *pTextItem = (XTextItem*)alloca( nItem * sizeof(XTextItem) ); - - for ( int nCurItem = 0; nCurItem < nItem; nCurItem++ ) + else + if ( pCvt->IsSingleByteEncoding(nEncoding) ) { - int nChars = pTextItem16[ nCurItem ].nchars; - char* pDstCharPtr = (char*)alloca( nChars * sizeof(char) ); - XChar2b* pSrcCharPtr = pTextItem16[ nCurItem ].chars; - - pTextItem[ nCurItem ].chars = pDstCharPtr; - pTextItem[ nCurItem ].nchars = nChars; - pTextItem[ nCurItem ].delta = pTextItem16[ nCurItem ].delta; - pTextItem[ nCurItem ].font = pTextItem16[ nCurItem ].font; - - for ( int nCurChar = 0; - nCurChar < nChars; - nCurChar++, pDstCharPtr++, pSrcCharPtr++ ) + // Single Byte encoding has to be padded + while ( n < nSize ) { - *pDstCharPtr = (char)pSrcCharPtr->byte2; + pTextChars[ m++ ] = 0x0; + pTextChars[ m++ ] = pBuffer[ n++ ]; } + pTextItem->nchars = nSize; } - - if ( nAngle != 0 ) + else { - for ( int nCurItem = 0; nCurItem < nItem; nCurItem++ ) + while ( n < nSize ) { - // XXX FIXME this is broken, because nX and nY is not sufficiently updated - XSetFont( pDisplay, nGC, pTextItem[ nItem ].font ); -#if !defined(USE_PSPRINT) && !defined(_USE_PRINT_EXTENSION_) - if ( XSalCanDrawRotString(pDisplay, nGC) ) - { - XSalDrawRotString( pDisplay, nDrawable, nGC, nX, nY, - pTextItem[ nCurItem ].chars, pTextItem[ nCurItem ].nchars, nAngle ); - } - else -#endif - { - XDrawString( pDisplay, nDrawable, nGC, nX, nY, - pTextItem[ nCurItem ].chars, pTextItem[ nCurItem ].nchars ); - } + pTextChars[ m++ ] = pBuffer[ n++ ]; } - } - else - { - XDrawText( pDisplay, nDrawable, nGC, nX, nY, pTextItem, nItem ); + pTextItem->nchars = nSize / 2; } } +//-------------------------------------------------------------------------- + // draw string vertically static void DrawVerticalString ( Display *pDisplay, Drawable nDrawable, GC nGC, @@ -915,183 +847,139 @@ void SalGraphicsData::DrawServerFontString( #endif - -// draw string in one of the fonts / encodings that are available in the -// extended font -void SalGraphicsData::DrawUnicodeString( int nX, int nY, - const sal_Unicode* pStr, int nLength ) +void +SalGraphicsData::DrawStringUCS2( int nX, int nY, const sal_Unicode* pStr, int nLength ) { -#ifdef USE_BUILTIN_RASTERIZER - if( mpServerSideFont != NULL ) - { - DrawServerFontString( nX, nY, pStr, nLength ); - return; - } -#endif + // plain Unicode, can handle all chars and can be handled straight forward + XFontStruct* pFontStruct = xFont_->GetFontStruct( RTL_TEXTENCODING_UNICODE ); - // sanity check - if ( xFont_ == NULL || nLength == 0 ) + if ( pFontStruct == NULL ) return; Display* pDisplay = GetXDisplay(); - GC nGC = SelectFont(); + GC nGC = SelectFont(); - rtl_TextEncoding nAsciiEnc = xFont_->GetAsciiEncoding(); - if ( nAsciiEnc == RTL_TEXTENCODING_UNICODE ) - { - if ( bFontVertical_ ) - DrawVerticalString( pDisplay, hDrawable_, nGC, nX, nY, pStr, nLength, xFont_ ); - else - { - // plain Unicode, can handle all chars and can be handled straight forward - XFontStruct* pFontStruct = xFont_->GetFontStruct( nAsciiEnc ); + XSetFont( pDisplay, nGC, pFontStruct->fid ); - if ( pFontStruct == NULL ) - return; + #ifdef OSL_LITENDIAN + sal_Unicode *pBuffer = (sal_Unicode*)alloca( nLength * sizeof(sal_Unicode) ); + for ( int i = 0; i < nLength; i++ ) + pBuffer[ i ] = SwapBytes(pStr[ i ]) ; + #else + sal_Unicode *pBuffer = const_cast(pStr); + #endif - XSetFont( pDisplay, nGC, pFontStruct->fid ); + XDrawString16( pDisplay, hDrawable_, nGC, nX, nY, (XChar2b*)pBuffer, nLength ); +} - #ifdef OSL_LITENDIAN - sal_Unicode *pBuffer = (sal_Unicode*)alloca( nLength * sizeof(sal_Unicode) ); - for ( int i = 0; i < nLength; i++ ) - pBuffer[ i ] = SwapBytes(pStr[ i ]) ; - #else - sal_Unicode *pBuffer = const_cast(pStr); - #endif +void +SalGraphicsData::DrawStringMB ( int nX, int nY, const sal_Unicode* pStr, int nLength ) +{ + // convert the string to a XTextItem16 with each item chars having the + // encoding matching the font of fontid + XTextItem16 *pTextItem = (XTextItem16*)alloca( nLength * sizeof(XTextItem16) ); + XChar2b *pMBChar = (XChar2b*) alloca( nLength * sizeof(XChar2b) ); - XDrawString16( pDisplay, hDrawable_, nGC, nX, nY, (XChar2b*)pBuffer, nLength ); - } - } - else - { - // convert the string to a XTextItem16 with each item chars having the - // encoding matching the font of fontid - XTextItem16 *pTextItem = (XTextItem16*)alloca( nLength * sizeof(XTextItem16) ); - XChar2b *pMBChar = (XChar2b*)alloca( nLength * sizeof(XChar2b) ); - memcpy( pMBChar, pStr, nLength * sizeof(XChar2b) ); + memcpy( pMBChar, pStr, nLength * sizeof(XChar2b) ); - rtl_TextEncoding nEncoding = nAsciiEnc; - XFontStruct* pFontStruct = xFont_->GetFontStruct( nEncoding ); + rtl_TextEncoding nEncoding; + XFontStruct *pFontStruct; - if ( pFontStruct == NULL ) - return; + VTextItemExt* pVTextItemExt; + if ( bFontVertical_ ) + pVTextItemExt = (VTextItemExt*)alloca( nLength * sizeof(VTextItemExt) ); - VTextItemExt* pVTextItemExt; - if ( bFontVertical_ ) - pVTextItemExt = (VTextItemExt*)alloca( nLength * sizeof(VTextItemExt) ); + for ( int nChar = 0, nItem = -1; nChar < nLength; nChar++ ) + { + rtl_TextEncoding nOldEnc; - SalConverterCache* pCvt = GetDisplay()->GetConverter(); - for ( int nChar = 0, nItem = -1; nChar < nLength; nChar++ ) - { - rtl_TextEncoding nOldEnc = nEncoding; - xFont_->GetFontStruct( pStr[nChar], &nEncoding, &pFontStruct, pCvt ); + if (nItem != -1) + nOldEnc = nEncoding; - if ( pFontStruct == NULL ) + if ( !(pFontStruct = xFont_->GetFontStruct(pStr[nChar], &nEncoding)) ) + if ( !(pFontStruct = mxFallbackFont->GetFontStruct(pStr[nChar], &nEncoding)) ) continue; - if ( (nItem != -1) && (pFontStruct->fid == pTextItem[ nItem ].font) ) - { - pTextItem[ nItem ].nchars += 1; - } - else - { - if ( nItem != -1 ) - ConvertTextItem16( &pTextItem[ nItem ], pCvt, nOldEnc ); + if ( (nItem != -1) && (pFontStruct->fid == pTextItem[ nItem ].font) ) + { + pTextItem[ nItem ].nchars += 1; + } + else + { + if ( nItem != -1 ) + ConvertTextItem16( &pTextItem[ nItem ], nOldEnc ); - ++nItem; + ++nItem; - pTextItem[ nItem ].chars = pMBChar + nChar; - pTextItem[ nItem ].delta = 0; - pTextItem[ nItem ].font = pFontStruct->fid; - pTextItem[ nItem ].nchars = 1; + pTextItem[ nItem ].chars = pMBChar + nChar; + pTextItem[ nItem ].delta = 0; + pTextItem[ nItem ].font = pFontStruct->fid; + pTextItem[ nItem ].nchars = 1; - if ( bFontVertical_ ) - { - pVTextItemExt[ nItem ].mnEncoding = nEncoding; - pVTextItemExt[ nItem ].mpString = pStr + nChar; - } + if ( bFontVertical_ ) + { + pVTextItemExt[ nItem ].mnEncoding = nEncoding; + pVTextItemExt[ nItem ].mpString = pStr + nChar; } } - ConvertTextItem16( &pTextItem[ nItem ], pCvt, nEncoding ); - ++nItem; + } + ConvertTextItem16( &pTextItem[ nItem ], nEncoding ); + ++nItem; - if ( bFontVertical_ ) - { - pVTextItemExt[ nItem - 1 ].mnEncoding = nEncoding; - DrawVerticalTextItem( pDisplay, hDrawable_, nGC, nX, nY, - pTextItem, nItem, pVTextItemExt, xFont_ ); - } - else - { -#ifndef USE_PSPRINT - if ( XSalIsDisplay( pDisplay ) ) - XDrawText16( pDisplay, nDrawable, nGC, nX, nY, pTextItem, nItem ); - else - XPrinterDrawText16( pDisplay, hDrawable_, nGC, nX, nY, - nFontOrientation_ * 64 / 10, pTextItem, nItem ); -#else - XDrawText16( pDisplay, hDrawable_, nGC, nX, nY, pTextItem, nItem ); -#endif - } + Display* pDisplay = GetXDisplay(); + GC nGC = SelectFont(); + + if ( bFontVertical_ ) + { + pVTextItemExt[ nItem - 1 ].mnEncoding = nEncoding; + DrawVerticalTextItem( pDisplay, hDrawable_, nGC, nX, nY, + pTextItem, nItem, pVTextItemExt, xFont_ ); + } + else + { + XDrawText16( pDisplay, hDrawable_, nGC, nX, nY, pTextItem, nItem ); } } -//-------------------------------------------------------------------------- - +// draw string in one of the fonts / encodings that are available in the +// extended font void SalGraphicsData::DrawText( long nX, long nY, - const sal_Unicode *pStr, USHORT nLen ) + const sal_Unicode* pStr, USHORT nLength ) { -#ifdef __notdef__ - // XXX Fix me this part is not unicode / multibyte aware - - // Bug: #45670# - // some monospace ISO8859-1 fonts have a hole between chars 128 and 159 - // some applications assume these characters have also the default width - if( ! bPrinter_ && - PITCH_FIXED == xFont_->GetFont()->mePitch && - nLen > 1 ) - { - XFontStruct *pXFS = GetFontInfo(); - long nWidth = xFont_->GetDim()->GetWidth(); + if (nLength == 0) + return; - if( xFont_->GetFixedWidth() != nWidth - || xFont_->GetDefaultWidth() != nWidth ) + #ifdef USE_BUILTIN_RASTERIZER + if( mpServerSideFont != NULL ) + { + DrawServerFontString( nX, nY, pStr, nLength ); + } + else + #endif + if ( xFont_ != NULL ) + { + if ( xFont_->GetAsciiEncoding() == RTL_TEXTENCODING_UNICODE ) { - unsigned int min_char = pXFS->min_char_or_byte2; - unsigned int max_char = pXFS->max_char_or_byte2; - XCharStruct *pXCS = pXFS->per_char - min_char; - - for( USHORT i = 0; i < nLen-1; i++ ) + if ( bFontVertical_ ) { - unsigned int c = ((unsigned char*)pStr)[i]; - - long nW = c < min_char || c > max_char || ! pXFS->per_char - ? xFont_->GetDefaultWidth() - : pXCS[c].width; - - if( nW != nWidth ) - { - long *pDXAry = new long[nLen]; - - for( i = 0; i < nLen; i++ ) - pDXAry[i] = nWidth * (i+1); - - DrawText( nX, nY, pStr, nLen, pDXAry ); - - delete pDXAry; - - return; - } + DrawVerticalString( GetXDisplay(), hDrawable_, SelectFont(), + nX, nY, pStr, nLength, xFont_ ); + } + else + { + DrawStringUCS2( nX, nY, pStr, nLength ); } } + else + { + DrawStringMB ( nX, nY, pStr, nLength ); + } } - -#endif /* __notdef__ */ - - DrawUnicodeString( nX, nY, pStr, nLen ); } +//-------------------------------------------------------------------------- + void SalGraphics::DrawText( long nX, long nY, const xub_Unicode* pStr, USHORT nLen ) { @@ -1154,7 +1042,7 @@ void SalGraphicsData::DrawText( long nX, long nY, } // draw every single character - DrawUnicodeString( nX, nY, pStr, 1 ); + DrawText( nX, nY, pStr, 1 ); Polygon aPolygon(1); Point aOrigin( nX, nY ); @@ -1165,7 +1053,7 @@ void SalGraphicsData::DrawText( long nX, long nY, aPolygon.Rotate( aOrigin, nFontOrientation_ ); aCharPos = aPolygon.GetPoint( 0 ); - DrawUnicodeString( aCharPos.X(), aCharPos.Y(), pStr+i, 1 ); + DrawText( aCharPos.X(), aCharPos.Y(), pStr+i, 1 ); } if( pTmpAry ) @@ -1384,7 +1272,6 @@ SalGraphics::GetDevFontList( ImplDevFontList *pList ) else #endif { - XlfdStorage* pFonts = _GetDisplay()->GetXlfdList(); for ( int nIdx = 0; nIdx < pFonts->GetCount(); nIdx++ ) @@ -1394,6 +1281,8 @@ SalGraphics::GetDevFontList( ImplDevFontList *pList ) pList->Add( pFontData ); } + // store data to bootstrap an X fallback font + #ifdef USE_BUILTIN_RASTERIZER aX11GlyphPeer.SetDisplay( maGraphicsData.GetXDisplay() ); GlyphCache::EnsureInstance( aX11GlyphPeer, false ); @@ -1421,7 +1310,9 @@ SalGraphics::GetDevFontList( ImplDevFontList *pList ) } rGC.FetchFontList( pList ); + #endif // USE_BUILTIN_RASTERIZER + } } @@ -1579,9 +1470,7 @@ SalGraphics::GetCharWidth( USHORT nChar1, USHORT nChar2, long *pWidthAry ) // the font should know it's metrics best SalDisplay *pSalDisplay = maGraphicsData.GetDisplay(); - nCharWidth = maGraphicsData.xFont_->GetCharWidth( - pSalDisplay->GetConverter(), nChar1, nChar2, pWidthAry, - maGraphicsData.bFontVertical_ ); + nCharWidth = maGraphicsData.xFont_->GetCharWidth( nChar1, nChar2, pWidthAry, maGraphicsData.mxFallbackFont ); // XXX sanity check, this may happen if the font cannot be loaded/queried // either because of a garbled fontpath or because of invalid fontfile diff --git a/vcl/unx/source/gdi/xfont.cxx b/vcl/unx/source/gdi/xfont.cxx index d4c821cc41f9..a8fbacd874bf 100644 --- a/vcl/unx/source/gdi/xfont.cxx +++ b/vcl/unx/source/gdi/xfont.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xfont.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: cp $ $Date: 2000-12-14 12:07:24 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -91,10 +91,12 @@ // don't have spacial font ExtendedFontStruct::ExtendedFontStruct( Display* pDisplay, - unsigned short nPixelSize, ExtendedXlfd* pXlfd, SalConverterCache* pCvt ) : + unsigned short nPixelSize, sal_Bool bVertical, ExtendedXlfd* pXlfd ) : mpDisplay( pDisplay ), mnPixelSize( nPixelSize ), - mpXlfd( pXlfd ) + mbVertical( bVertical ), + mpXlfd( pXlfd ), + mnCachedEncoding( RTL_TEXTENCODING_DONTKNOW ) { // member functions rely on zero initialized pointer for checking of // already loaded fonts @@ -107,7 +109,7 @@ ExtendedFontStruct::ExtendedFontStruct( Display* pDisplay, mpVXFontStruct[nIdx] = (XFontStruct**)calloc (VCLASS_FONT_NUM, sizeof (XFontStruct*) ); } - mnDefaultWidth = GetDefaultWidth( pCvt ); + mnDefaultWidth = GetDefaultWidth(); } ExtendedFontStruct::~ExtendedFontStruct() @@ -131,6 +133,12 @@ ExtendedFontStruct::GetAsciiEncoding( int *pAsciiRange ) const return mpXlfd->GetAsciiEncoding( pAsciiRange ); } +FontPitch +ExtendedFontStruct::GetSpacing( rtl_TextEncoding nEncoding ) +{ + return mpXlfd->GetSpacing( nEncoding ); +} + int ExtendedFontStruct::LoadEncoding( rtl_TextEncoding nEncoding ) { @@ -236,12 +244,13 @@ ExtendedFontStruct::ToImplFontMetricData(ImplFontMetricData *pFontMetric) } Bool -ExtendedFontStruct::Match( const ExtendedXlfd *pXlfd, int nPixelSize ) const +ExtendedFontStruct::Match( const ExtendedXlfd *pXlfd, + int nPixelSize, sal_Bool bVertical ) const { if( mpXlfd != pXlfd ) return FALSE; - return mnPixelSize == nPixelSize; + return (mnPixelSize == nPixelSize) && (mbVertical == bVertical); } // Get an appropriate x-font that contains a glyph for the given unicode @@ -253,35 +262,34 @@ ExtendedFontStruct::Match( const ExtendedXlfd *pXlfd, int nPixelSize ) const // EncodingHasChar() to fail and thus bootstraps the encoding, otherwise // make sure that the initial value of pFontInOut matches the encoding and // that the encoding is valid for the font. -Bool -ExtendedFontStruct::GetFontStruct( sal_Unicode nChar, - rtl_TextEncoding *pEncodingInOut, XFontStruct **pFontInOut, - SalConverterCache *pCvt ) +XFontStruct* +ExtendedFontStruct::GetFontStruct( sal_Unicode nChar, rtl_TextEncoding *pEncoding ) { - if ( pCvt->EncodingHasChar(*pEncodingInOut, nChar) ) + SalConverterCache *pCvt = SalConverterCache::GetInstance(); + + if ( pCvt->EncodingHasChar(mnCachedEncoding, nChar) ) { - return True; + *pEncoding = mnCachedEncoding; + return GetFontStruct (mnCachedEncoding); } else { for ( int nIdx = 0; nIdx < mpXlfd->NumEncodings(); nIdx++ ) { rtl_TextEncoding nEnc = mpXlfd->GetEncoding(nIdx); - if ( (nEnc != *pEncodingInOut) - && pCvt->EncodingHasChar(nEnc, nChar) ) + if ((nEnc != mnCachedEncoding) && pCvt->EncodingHasChar(nEnc, nChar)) { - *pEncodingInOut = nEnc; - *pFontInOut = GetFontStruct( nEnc ); - if (*pFontInOut != NULL) - return True; + mnCachedEncoding = nEnc; + *pEncoding = mnCachedEncoding; + return GetFontStruct (mnCachedEncoding); } } } - return False; + *pEncoding = RTL_TEXTENCODING_DONTKNOW; + return NULL; } - // --------------------------------------------------------------------------- // utility functions to handle xfontstruct information, this is all to // calculate charwidth information @@ -346,49 +354,10 @@ QueryCharWidth8( XFontStruct* pXFontStruct, sal_Char nChar, return CharExists( &aBoundingBox ) ? aBoundingBox.width : nDefaultWidth; } -// the default width is the width of the question mark since this is the -// character which is displayed for unconvertable unicode chars sal_Size -ExtendedFontStruct::GetDefaultWidth( SalConverterCache* pCvt ) +ExtendedFontStruct::GetDefaultWidth() { - rtl_TextEncoding nEncoding = mpXlfd->GetAsciiEncoding(); - XFontStruct* pXFontStruct = GetFontStruct( nEncoding ); - - if ( pXFontStruct != NULL ) - { - sal_Unicode nQuestionMark = 0x3f; - sal_MultiByte nChar; - sal_Char pBuffer[8]; - - sal_Size nSize = ConvertStringUTF16( &nQuestionMark, 1, pBuffer, - sizeof(pBuffer), pCvt->GetU2TConverter(nEncoding) ); - - // XXX FIXME - if ( (nEncoding == RTL_TEXTENCODING_GB_2312) - || (nEncoding == RTL_TEXTENCODING_EUC_KR) ) - { - for (int n_char = 0; n_char < nSize; n_char++ ) - pBuffer[ n_char ] &= 0x7F; - } - - if ( nSize == 2 ) - { - nChar = ((sal_MultiByte)pBuffer[0] << 8) - + (sal_MultiByte)pBuffer[1]; - return QueryCharWidth16( mpDisplay, pXFontStruct->fid, nChar, 0 ); - } - else - if ( nSize == 1 ) - { - return QueryCharWidth8( pXFontStruct, pBuffer[0], 0 ); - } - else - { - return QueryCharWidth8( pXFontStruct, nQuestionMark, 0 ); - } - } - - return 0; + return (mnPixelSize + 1) / 2; } void @@ -481,7 +450,7 @@ ExtendedFontStruct::GetCharWidth8( sal_Unicode nFrom, sal_Unicode nTo, // Handle utf16 encoded fonts, which do not require conversion sal_Size ExtendedFontStruct::GetCharWidthUTF16( sal_Unicode nFrom, sal_Unicode nTo, - long *pWidthArray, Bool bVertical ) + long *pWidthArray ) { if ( !(nFrom <= nTo) ) return 0; @@ -493,7 +462,7 @@ ExtendedFontStruct::GetCharWidthUTF16( sal_Unicode nFrom, sal_Unicode nTo, return 0; // query the font metrics - if ( bVertical ) + if ( mbVertical ) { GetVerticalCharWidth( RTL_TEXTENCODING_UNICODE, nFrom, nTo, nFrom, nTo, pWidthArray ); @@ -532,51 +501,51 @@ ExtendedFontStruct::GetCharWidthUTF16( sal_Unicode nFrom, sal_Unicode nTo, // handle non unicode fonts that are converted into encoding matching the // font in fontstruct, 8 and 16 bit fonts are handled the same way sal_Size -ExtendedFontStruct::GetCharWidth16( SalConverterCache *pCvt, - sal_Unicode nFrom, sal_Unicode nTo, long *pWidthArray, Bool bVertical ) +ExtendedFontStruct::GetCharWidth16( sal_Unicode nFrom, sal_Unicode nTo, + long *pWidthArray, ExtendedFontStruct *pFallback ) { if ( !(nFrom <= nTo) ) return 0; - rtl_TextEncoding nEncoding = mpXlfd->GetAsciiEncoding(); - XFontStruct *pXFontStruct = GetFontStruct( nEncoding ); - - if ( pXFontStruct == NULL ) - return 0; - - unsigned char pBuffer[16]; + sal_Char pBuffer[16]; sal_MultiByte nChar; + SalConverterCache *pCvt = SalConverterCache::GetInstance(); + for ( sal_Int32 nIdx = nFrom ; nIdx <= nTo ; nIdx++, pWidthArray++ ) { - Bool bValid; FontPitch nSpacing; sal_Size nSize; // get a matching fontstruct - if ( bValid = GetFontStruct( nIdx, &nEncoding, &pXFontStruct, pCvt ) ) + rtl_TextEncoding nEncoding; + XFontStruct *pXFontStruct; + + if ( (pXFontStruct = GetFontStruct(nIdx, &nEncoding)) != NULL ) + { + nSpacing = GetSpacing( nEncoding ); + } + else + if ( (pFallback != NULL) + && ((pXFontStruct = pFallback->GetFontStruct(nIdx, &nEncoding)) != NULL) ) + { + nSpacing = pFallback->GetSpacing( nEncoding ); + } + + if ( pXFontStruct ) { - nSpacing = mpXlfd->GetSpacing( nEncoding ); sal_Unicode nUniIdx = (sal_Unicode)nIdx; - nSize = ConvertStringUTF16( &nUniIdx, 1, - (sal_Char*)pBuffer, sizeof(pBuffer), - pCvt->GetU2TConverter(nEncoding) ); - // XXX FIXME - if ( (nEncoding == RTL_TEXTENCODING_GB_2312) - || (nEncoding == RTL_TEXTENCODING_EUC_KR) ) - { - for (int n_char = 0; n_char < nSize; n_char++ ) - pBuffer[ n_char ] &= 0x7F; - } + nSize = pCvt->ConvertStringUTF16( &nUniIdx, 1, pBuffer, sizeof(pBuffer), + nEncoding ); } // query font metrics - if ( bValid && (nSize == 1 || nSize == 2) ) + if ( pXFontStruct && (nSize == 1 || nSize == 2) ) { - nChar = nSize == 1 ? (sal_MultiByte)pBuffer[0] : + nChar = nSize == 1 ? (sal_MultiByte)pBuffer[0] : ((sal_MultiByte)pBuffer[0] << 8) + (sal_MultiByte)pBuffer[1]; - if ( bVertical ) + if ( mbVertical ) { GetVerticalCharWidth( nEncoding, nIdx, nIdx, nChar, nChar, pWidthArray ); } @@ -615,8 +584,8 @@ ExtendedFontStruct::GetCharWidth16( SalConverterCache *pCvt, } sal_Size -ExtendedFontStruct::GetCharWidth( SalConverterCache *pCvt, - sal_Unicode nFrom, sal_Unicode nTo, long *pWidthArray, Bool bVertical ) +ExtendedFontStruct::GetCharWidth( sal_Unicode nFrom, sal_Unicode nTo, long *pWidthArray, + ExtendedFontStruct *pFallback ) { int nAsciiRange; sal_Size nConverted = 0; @@ -628,7 +597,7 @@ ExtendedFontStruct::GetCharWidth( SalConverterCache *pCvt, { // if we have a unicode encoded system font than we get the charwidth // straight forward - nConverted = GetCharWidthUTF16( nFrom, nTo, pWidthArray, bVertical ); + nConverted = GetCharWidthUTF16( nFrom, nTo, pWidthArray ); } else { @@ -636,15 +605,15 @@ ExtendedFontStruct::GetCharWidth( SalConverterCache *pCvt, { // optimize the most frequent case, requesting only the latin1 // chars which are mappable to a single encoding - nConverted = GetCharWidth8( nFrom, min(nAsciiRange, nTo), - pWidthArray, nEncoding ); + sal_Unicode nMinTo = min(nAsciiRange, nTo); + nConverted = GetCharWidth8( nFrom, nMinTo, pWidthArray, nEncoding ); } // if further requests are pending, then the according unicode // codepoint has to be dispatched to one of the system fonts and // converted to this fonts encoding - nConverted += GetCharWidth16( pCvt, nFrom + nConverted, nTo, - pWidthArray + nConverted, bVertical ); + nConverted += GetCharWidth16( nFrom + nConverted, nTo, pWidthArray + nConverted, + pFallback ); } return nConverted; diff --git a/vcl/unx/source/gdi/xlfd_attr.cxx b/vcl/unx/source/gdi/xlfd_attr.cxx index 44afc6f17ea4..9c31a082094e 100644 --- a/vcl/unx/source/gdi/xlfd_attr.cxx +++ b/vcl/unx/source/gdi/xlfd_attr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xlfd_attr.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: cp $ $Date: 2000-12-19 17:55:50 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -144,35 +144,61 @@ Attribute::TagFeature( unsigned short nFeature ) { mnFeature |= XLFD_FEATURE_NARROW; } + if ( (nFeature & XLFD_FEATURE_OL_CURSOR) && (strcmp(mpName, "open look cursor") == 0) ) { mnFeature |= XLFD_FEATURE_OL_CURSOR; } + if ( (nFeature & XLFD_FEATURE_OL_GLYPH) && (strcmp(mpName, "open look glyph") == 0) ) { mnFeature |= XLFD_FEATURE_OL_GLYPH; } + if ( (nFeature & XLFD_FEATURE_APPLICATION_FONT) && ( (strcmp(mpName, "interface user") == 0) || (strcmp(mpName, "interface system") == 0))) { mnFeature |= XLFD_FEATURE_APPLICATION_FONT; } - if ( (nFeature & XLFD_FEATURE_INTERFACE_FONT) - && ( (strcmp(mpName, "arial") == 0) /* european */ - || (strcmp(mpName, "helvetica") == 0) - || (strcmp(mpName, "hg mincho l") == 0) /* solaris: japanese */ - || (strcmp(mpName, "minchol") == 0) /* turbo linux: jisx201 / jisx208 */ - || (strcmp(mpName, "heiseimin") == 0) /* */ - || (strcmp(mpName, "myeongjo") == 0) /* solaris: korean */ - || (strcmp(mpName, "kai") == 0) /* solaris: chinese */ - || (strcmp(mpName, "ar pl mingti2l big5") == 0) /* turbo linux: chinese */ - ) - ) + + if (nFeature & XLFD_FEATURE_INTERFACE_FONT) { - mnFeature |= XLFD_FEATURE_INTERFACE_FONT; + // european + if ( (strcmp(mpName, "arial") == 0) + || (strcmp(mpName, "helvetica") == 0)) + { + mnFeature |= (XLFD_FEATURE_INTERFACE_FONT | XLFD_FEATURE_INTERFACE_FONT_HIGQ); + } + else + if ( (strcmp(mpName, "charter") == 0) /* last exit on linux */ + || (strcmp(mpName, "lucidux sans") == 0)) + { + mnFeature |= (XLFD_FEATURE_INTERFACE_FONT | XLFD_FEATURE_INTERFACE_FONT_MEDQ); + } + else + // japanese + if ( (strcmp(mpName, "hg mincho l") == 0) /* Solaris: jisx0208 jisx0201 */ + || (strcmp(mpName, "heiseimin") == 0) /* Solaris: jisx0212 */ + || (strcmp(mpName, "minchol") == 0)) /* TurboLinux */ + { + mnFeature |= XLFD_FEATURE_INTERFACE_FONT; + } + else + // chinese + if ( (strcmp(mpName, "kai") == 0) /* Solaris */ + || (strcmp(mpName, "ar pl mingti2l big5") == 0)) /* TurboLinux */ + { + mnFeature |= XLFD_FEATURE_INTERFACE_FONT; + } + else + // korean + if ( (strcmp(mpName, "myeongjo") == 0)) /* Solaris */ + { + mnFeature |= XLFD_FEATURE_INTERFACE_FONT; + } } if ( nFeature & XLFD_FEATURE_REDUNDANTSTYLE ) diff --git a/vcl/unx/source/gdi/xlfd_attr.hxx b/vcl/unx/source/gdi/xlfd_attr.hxx index cadd295af8d5..aa43c7897741 100644 --- a/vcl/unx/source/gdi/xlfd_attr.hxx +++ b/vcl/unx/source/gdi/xlfd_attr.hxx @@ -2,9 +2,9 @@ * * $RCSfile: xlfd_attr.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: cp $ $Date: 2000-12-13 20:36:59 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -112,13 +112,16 @@ extern "C" { typedef rtl_TextEncoding(*AttributeClassifierT)(const char* pStr); } -#define XLFD_FEATURE_NONE 0x00 -#define XLFD_FEATURE_NARROW 0x01 -#define XLFD_FEATURE_OL_GLYPH 0x02 -#define XLFD_FEATURE_OL_CURSOR 0x04 -#define XLFD_FEATURE_REDUNDANTSTYLE 0x08 -#define XLFD_FEATURE_APPLICATION_FONT 0x10 -#define XLFD_FEATURE_INTERFACE_FONT 0x20 +#define XLFD_FEATURE_NONE 0x0000 +#define XLFD_FEATURE_NARROW 0x0001 +#define XLFD_FEATURE_OL_GLYPH 0x0002 +#define XLFD_FEATURE_OL_CURSOR 0x0004 +#define XLFD_FEATURE_REDUNDANTSTYLE 0x0008 +#define XLFD_FEATURE_APPLICATION_FONT 0x0010 + +#define XLFD_FEATURE_INTERFACE_FONT 0x0020 +#define XLFD_FEATURE_INTERFACE_FONT_MEDQ 0x0040 +#define XLFD_FEATURE_INTERFACE_FONT_HIGQ 0x0080 // --------------------------------------------------------------------------- // diff --git a/vcl/unx/source/gdi/xlfd_extd.cxx b/vcl/unx/source/gdi/xlfd_extd.cxx index fd5eeb410a51..4576225f7ff4 100644 --- a/vcl/unx/source/gdi/xlfd_extd.cxx +++ b/vcl/unx/source/gdi/xlfd_extd.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xlfd_extd.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: cp $ $Date: 2000-12-15 14:41:34 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -751,21 +751,38 @@ VirtualXlfd::AddEncoding( const Xlfd *pXlfd ) return False; } +int +VirtualXlfd::GetFontQuality (unsigned short nFamily) +{ + Attribute *pFamily = mpFactory->RetrieveFamily(nFamily); + + if (pFamily->HasFeature(XLFD_FEATURE_INTERFACE_FONT_HIGQ)) + return 32; + if (pFamily->HasFeature(XLFD_FEATURE_INTERFACE_FONT_MEDQ)) + return 16; + return 0; +} + Bool -VirtualXlfd::AddEncoding( const ExtendedXlfd *pXlfd ) +VirtualXlfd::AddEncoding( const ExtendedXlfd *pXlfd) { + mpFactory = pXlfd->mpFactory; + + int nFontQuality = GetFontQuality (pXlfd->mnFamily); + for (int i = 0; i < pXlfd->NumEncodings(); i++) { rtl_TextEncoding nEncoding = pXlfd->GetEncoding(i); - if (!HasEncoding(nEncoding)) + int nIdx = GetEncodingIdx( nEncoding ); + if ( nIdx < 0 /* !HasEncoding(nEncoding) */) { - /* deep copy of the xlfd information */ - mpFactory = pXlfd->mpFactory; + /* XXX should be obsolete since all info is in mpExtEncodingInfo */ mnFoundry = pXlfd->mnFoundry; mnFamily = pXlfd->mnFamily; mnWeight = pXlfd->mnWeight; mnSlant = pXlfd->mnSlant; mnSetwidth = pXlfd->mnSetwidth; + /* XXX end of obsolete */ mpEncodingInfo = (EncodingInfo*)Realloc( mpEncodingInfo, (mnEncodings + 1) * sizeof(EncodingInfo) ); @@ -776,6 +793,12 @@ VirtualXlfd::AddEncoding( const ExtendedXlfd *pXlfd ) mnEncodings++; } + else + if (nFontQuality > GetFontQuality (mpExtEncodingInfo[nIdx].mnFamily)) + { + mpEncodingInfo[ nIdx ] = pXlfd->mpEncodingInfo[i]; + mpExtEncodingInfo[ nIdx ] = pXlfd; + } } return mnEncodings > 0 ? True : False; @@ -893,7 +916,8 @@ XlfdStorage::~XlfdStorage() XlfdStorage::XlfdStorage() : mnCount( 0 ), mnSize( 0 ), - mpList( NULL ) + mpList( NULL ), + mpInterfaceFont( NULL ) { } @@ -989,7 +1013,14 @@ XlfdStorage::InterfaceFont (AttributeProvider* pFactory) } if (pVirtualFont->NumEncodings() > 0) + { + mpInterfaceFont = pVirtualFont; Add (pVirtualFont); + } + else + { + delete pVirtualFont; + } } // ------ bitmap font list -------------------------------------------------- diff --git a/vcl/unx/source/gdi/xlfd_extd.hxx b/vcl/unx/source/gdi/xlfd_extd.hxx index 478dd0dfe659..f4efee462ecd 100644 --- a/vcl/unx/source/gdi/xlfd_extd.hxx +++ b/vcl/unx/source/gdi/xlfd_extd.hxx @@ -2,9 +2,9 @@ * * $RCSfile: xlfd_extd.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: hjs $ $Date: 2000-12-14 13:07:49 $ + * last change: $Author: cp $ $Date: 2001-03-19 08:31:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -263,6 +263,8 @@ class XlfdStorage { { return mnCount; } const ExtendedXlfd* Get(int nIdx) const; void InterfaceFont( AttributeProvider* pFactory); + const ExtendedXlfd* GetInterfaceFont () const + { return mpInterfaceFont; } #ifdef DEBUG void Dump() const ; #endif @@ -275,6 +277,7 @@ class XlfdStorage { unsigned short mnSize; const ExtendedXlfd** mpList; + const ExtendedXlfd* mpInterfaceFont; }; // list of fonts specific for bitmap fonts @@ -292,11 +295,15 @@ class BitmapXlfdStorage : public XlfdStorage { class VirtualXlfd : public ExtendedXlfd { + private: + + int GetFontQuality (unsigned short nFamily); + public: VirtualXlfd(); virtual ~VirtualXlfd(); virtual Bool AddEncoding( const Xlfd *pXlfd ); - Bool AddEncoding( const ExtendedXlfd *pXlfd ); + Bool AddEncoding( const ExtendedXlfd *pXlfd); virtual void ToString( ByteString &rString, unsigned short nPixelSize, rtl_TextEncoding nEncoding ) const ; -- cgit