FLTK logo

[master] d325fa5 - Replace call to CreateFont() by call to CreateFontW().

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] d325fa5 - Replace call to CreateFont() by call to CreateFontW(). "ManoloFLTK" Aug 13, 2022  
 
commit d325fa504e4a4e2a456a646a4159a43a8dfac4fd
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sat Aug 13 12:25:04 2022 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sat Aug 13 12:25:04 2022 +0200

    Replace call to CreateFont() by call to CreateFontW().

 src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx
index 2315c87..82bf207 100644
--- src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx
+++ src/drivers/GDI/Fl_GDI_Graphics_Driver_font.cxx
@@ -208,6 +208,9 @@ void Fl_GDI_Graphics_Driver::font_name(int num, const char *name) {
 
 
 static int fl_angle_ = 0;
+// Unicode string buffer
+static unsigned short *wstr = NULL;
+static int wstr_len    = 0;
 
 #ifndef FL_DOXYGEN
 Fl_GDI_Font_Descriptor::Fl_GDI_Font_Descriptor(const char* name, Fl_Fontsize fsize) : Fl_Font_Descriptor(name,fsize) {
@@ -220,7 +223,14 @@ Fl_GDI_Font_Descriptor::Fl_GDI_Font_Descriptor(const char* name, Fl_Fontsize fsi
   case ' ': break;
   default: name--;
   }
-  fid = CreateFont(
+  int wn = fl_utf8toUtf16(name, strlen(name), wstr, wstr_len);
+  if (wn >= wstr_len) {
+    wstr = (unsigned short*) realloc(wstr, sizeof(unsigned short) * (wn + 1));
+    wstr_len = wn + 1;
+    wn = fl_utf8toUtf16(name, strlen(name), wstr, wstr_len);
+  }
+
+  fid = CreateFontW(
     -fsize, // negative makes it use "char size"
     0,              // logical average character width
     fl_angle_*10,                   // angle of escapement
@@ -234,7 +244,7 @@ Fl_GDI_Font_Descriptor::Fl_GDI_Font_Descriptor(const char* name, Fl_Fontsize fsi
     CLIP_DEFAULT_PRECIS,// clipping precision
     DEFAULT_QUALITY,    // output quality
     DEFAULT_PITCH,      // pitch and family
-    name                // pointer to typeface name string
+    (LPCWSTR)wstr       // pointer to typeface name string
     );
   angle = fl_angle_;
   HDC gc = (HDC)fl_graphics_driver->gc();
@@ -338,12 +348,6 @@ Fl_Fontsize Fl_GDI_Graphics_Driver::size_unscaled() {
   return -1;
 }
 
-
-// Unicode string buffer
-static unsigned short *wstr = NULL;
-static int wstr_len    = 0;
-
-
 double Fl_GDI_Graphics_Driver::width_unscaled(const char* c, int n) {
   int i = 0;
   if (!font_descriptor()) return -1.0;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.