Re: #9222 non-western locale and windows font problem (PATCH)

From: Tomas Frydrych <tomasfrydrych_at_yahoo.co.uk>
Date: Tue Aug 23 2005 - 13:57:32 CEST

Hi Roland,

That looks good to me.

Tomas

Roland Kay wrote:
> Hi Guys,
>
> I've been investigating #9211. It seems that the windows font API
> functions expect font names in the native encoding rather than UTF-8.
> At the moment we pass in UTF-8 and so windows never finds the required
> font. The attached patch fixes this.
>
> Could someone just check that this is OK? In particular, is the use of
> XAP_EncodingManager::get_instance() correct?
>
> Best wishes,
>
> R.
>
>
> ------------------------------------------------------------------------
>
> --- gr_Win32Graphics.cpp 2005-08-23 04:44:43.633780128 +0100
> +++ gr_Win32Graphics.cpp-new 2005-08-23 04:45:11.129600128 +0100
> @@ -36,6 +36,7 @@
> #include "xap_Frame.h"
> #include "xap_Dialog_Id.h"
> #include "xap_Win32Dlg_Print.h"
> +#include "xap_EncodingManager.h"
>
> #include "ut_debugmsg.h"
> #include "ut_assert.h"
> @@ -330,7 +331,18 @@
> else if (0 == UT_stricmp(pszFontFamily, "monospace"))
> lf.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN;
> else
> - strcpy(lf.lfFaceName, pszFontFamily);
> + {
> + // NB: lf.lfFaceName is a statically allocated char buffer of len
> + // LFFACESIZE. strToNative() will truncate the string at 500 bytes,
> + // but as LFFACESIZE is generally 32, this shouldn't matter.
> + //
> + // This convertion is needed because the windows API expects fontname
> + // is the native encoding and later lf will be passing to a windows
> + // API funcion (CreateFontIndirect()).
> + strncpy(lf.lfFaceName,
> + getApp()->getEncodingManager()->strToNative(pszFontFamily, "UTF-8", false),
> + LF_FACESIZE);
> + }
>
> // Get character set value from the font itself
> LOGFONT enumlf = { 0 };
> @@ -1382,7 +1394,11 @@
> else if (UT_stricmp(szFontName, "monospace") == 0)
> lf.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN;
> else
> - strcpy(lf.lfFaceName, szFontName);
> + {
> + strncpy(lf.lfFaceName,
> + XAP_EncodingManager::get_instance()->strToNative(szFontName, "UTF-8", false),
> + LF_FACESIZE);
> + }
>
> // let the system create the font with the given name or
> // properties and then query it and see what was actually

        
        
                
___________________________________________________________
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
Received on Tue Aug 23 13:58:33 2005

This archive was generated by hypermail 2.1.8 : Tue Aug 23 2005 - 13:58:33 CEST