Rafal wrote:

After research, currently the situation is following.

Unicode strings are not displayed in win98 (especiall older ones I guess, no
libcows/MSLU).

Question:
Can anyone PLEASE paste WinAPI code, that will display on dc (using
CreateFontIndirectA and TextOutA) how to display string say "Łódź" on
windows 98/95?
This string does consist only of characters from one windows code page
(typicall, windows-cp-1250).

My work:
It seems the best way would be to use TextOutA, and as string pass there not
UTF-8 data, but extended ascii (windows-cp-1250) data.  
(and similar for other code pages).

I almost did that, but... from what I seen, the font on win98 did not
contain all needed glyps in one code page... strange.

Well I will work a bit.


Attaching a random WIP patch, it also contains
* public detect OS function (not only win32)
* has_unicode now publid (not only win32)
* detail - show extra version info

I hope to fix that, but if anyone can contribute a working example...
Surprisingly, even nowdays microsoft developers do not know easly how to do
the above... Well, I guess win98 _is_ very old... 


-- 
Rafał Maj
Software developer
Index: src/win32/fltk_theme.cxx
===================================================================
--- src/win32/fltk_theme.cxx	(revision 6151)
+++ src/win32/fltk_theme.cxx	(working copy)
@@ -35,11 +35,10 @@
 #include <fltk/x.h>
 #include <limits.h>
 #include <wchar.h>
+#include <fltk/run.h>
 
 using namespace fltk;
 
-extern int has_unicode();
-
 ////////////////////////////////////////////////////////////////
 
 #ifndef SPI_GETWHEELSCROLLLINES
Index: src/win32/list_fonts.cxx
===================================================================
--- src/win32/list_fonts.cxx	(revision 6151)
+++ src/win32/list_fonts.cxx	(working copy)
@@ -31,11 +31,10 @@
 #include <string.h>
 #include <stdlib.h>
 #include <config.h>
+#include <fltk/run.h>
 
 using namespace fltk;
 
-extern int has_unicode();
-
 int Font::encodings(const char**& arrayp) {
   // CET - FIXME - What about this encoding stuff?
   // WAS: we need some way to find out what charsets are supported
Index: src/win32/run.cxx
===================================================================
--- src/win32/run.cxx	(revision 6151)
+++ src/win32/run.cxx	(working copy)
@@ -848,14 +848,33 @@
 ////////////////////////////////////////////////////////////////
 // Determite if windows has unicode capability
 
-int has_unicode()
+const char* fltk::os_name_family_id() { // some short name/id like Win98 WinNT OSX LINUX etc.
+	bool tested=0;
+  OSVERSIONINFOA os;
+	if (!tested) {
+	  os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
+  	GetVersionExA(&os);
+		tested=1;
+	}
+	if (os.dwPlatformId==VER_PLATFORM_WIN32_NT) return "WinNT";
+	return "Win9x";
+}
+
+const char* fltk::os_name_full() { // later this can be more elaborated version name
+	// TODO: http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx
+	// TODO: http://www.mvps.org/access/api/api0055.htm
+	return os_name_family_id();
+}
+
+int fltk::has_unicode() // see run.h
 {
   static int has_unicode = -1;
   if (has_unicode == -1) {
     OSVERSIONINFOA os;
     os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
     GetVersionExA(&os);
-    has_unicode = (os.dwPlatformId==VER_PLATFORM_WIN32_NT);
+		if (0==strcmp(os_name_family_id(),"Win9x")) has_unicode=0;
+		else has_unicode=2;
   }
   return has_unicode;
 }
@@ -2496,6 +2515,7 @@
 HFONT WINAPI ansi_CreateFontIndirectW(CONST LOGFONTW *lFont)
 {
   LOGFONTA lFontA;
+	// http://msdn.microsoft.com/en-us/library/aa741230(VS.85).aspx
   lFontA.lfCharSet      = lFont->lfCharSet;
   lFontA.lfClipPrecision= lFont->lfClipPrecision;
   lFontA.lfEscapement   = lFont->lfEscapement;
@@ -2506,6 +2526,7 @@
   lFontA.lfPitchAndFamily = lFont->lfPitchAndFamily;
   lFontA.lfQuality      = lFont->lfQuality;
   lFontA.lfStrikeOut    = lFont->lfStrikeOut;
+  lFontA.lfCharSet      = lFont->lfCharSet;
   lFontA.lfUnderline    = lFont->lfUnderline;
   lFontA.lfWeight       = lFont->lfWeight;
   lFontA.lfWidth        = lFont->lfWidth;
Index: src/win32/Font.cxx
===================================================================
--- src/win32/Font.cxx	(revision 6151)
+++ src/win32/Font.cxx	(working copy)
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <fltk/math.h>
 #include <fltk/utf.h>
+#include <fltk/run.h>
 
 using namespace fltk;
 
@@ -87,6 +88,7 @@
   int height = -size;
 
   LOGFONTW lf;
+	// http://msdn.microsoft.com/en-us/library/ms533931(VS.85).aspx
   memset( &lf, 0, sizeof(lf) );
   lf.lfHeight         = height; // use "char size"
   lf.lfWidth          = 0L;
@@ -224,7 +226,10 @@
 }
 
 // we need to decode the encoding somehow!
-static int charset = DEFAULT_CHARSET;
+int fltk::windows_charset = BALTIC_CHARSET  ; // the default encoding; for non-unicode windows.  will be just -1 on other platforms.
+//
+// default:
+// DEFAULT_CHARSET
 
 void fltk::setfont(Font* font, float psize) {
 
@@ -234,7 +239,7 @@
   unsigned size = unsigned(psize);
 
   if (font == current_font_ && current->size == size &&
-      current->charset == charset) return;
+      current->charset == windows_charset) return;
   current_font_ = font; current_size_ = psize;
 
   // binary search the fontsizes we have generated already
@@ -245,7 +250,7 @@
     unsigned c = (a+b)/2;
     FontSize* f = array[c];
     int d = f->size-size;
-    if (!d) d = f->charset - charset;
+    if (!d) d = f->charset - windows_charset;
     if (d < 0) a = c+1;
     else if (d > 0) b = c;
     else {current = f; return;}
@@ -261,7 +266,7 @@
     memmove(array+a+1, array+a, (n-a)*sizeof(FontSize*));
   }
   ((IFont*)font)->numsizes = n+1;
-  current = array[a] = new FontSize(font->name_, font->attributes_, size, charset);
+  current = array[a] = new FontSize(font->name_, font->attributes_, size, windows_charset);
 }
 
 float fltk::getascent()  { return float(current->metr.tmAscent); }
@@ -292,13 +297,29 @@
   wchar_t localbuffer[WCBUFLEN];
   wchar_t* buffer = localbuffer;
   wchar_t* mallocbuffer = 0;
-  int count = utf8towc(text, n, buffer, WCBUFLEN);
-  if (count >= WCBUFLEN) {
-    buffer = mallocbuffer = new wchar_t[count+1];
-    count = utf8towc(text, n, buffer, count+1);
-  }
-  TextOutW(dc, int(floorf(x+.5f)), int(floorf(y+.5f)), buffer, count);
-  delete[] mallocbuffer;
+
+	if (fltk::has_unicode()) {
+	  int count = utf8towc(text, n, buffer, WCBUFLEN);
+		if (count >= WCBUFLEN) {
+  	  buffer = mallocbuffer = new wchar_t[count+1];
+   	 count = utf8towc(text, n, buffer, count+1);
+	  }
+	  TextOutW(dc, int(floorf(x+.5f)), int(floorf(y+.5f)), buffer, count);
+  	delete[] mallocbuffer;
+	}
+	else {
+		// TODO:
+		// WARNING XXX TOTALLY EXPERIMENTAL - this probably brakes things
+		// even more in 9x for now.
+		/*
+	  int count = utf8towc(text, n, buffer, WCBUFLEN);
+		if (count >= WCBUFLEN) {
+ 	  	buffer = mallocbuffer = new wchar_t[count+1];
+			count = utf8towc(text, n, buffer, count+1);
+	  }*/
+		int count = strlen(text);
+	  TextOutA(dc, int(floorf(x+.5f)), int(floorf(y+.5f)), text, count);
+	}
 }
 
 //
Index: src/osx/run.cxx
===================================================================
--- src/osx/run.cxx	(revision 6151)
+++ src/osx/run.cxx	(working copy)
@@ -1923,6 +1923,21 @@
   return CreatedWindow::find(w)->xid;
 }
 
+
+const char* fltk::os_name_family_id() { // some short name/id like Win98 WinNT OSX X11 etc.
+	return "OSX";
+}
+
+const char* fltk::os_name_full() { // later this can be more elaborated version name
+	return os_name_family_id();
+}
+
+int fltk::has_unicode() // see run.h
+{
+	return 3; // good os - unicode
+	// TODO: detect really old, pre-unicode mac?
+}
+
 //
 // End of "$Id$".
 //
Index: src/osx/Font.cxx
===================================================================
--- src/osx/Font.cxx	(revision 6151)
+++ src/osx/Font.cxx	(working copy)
@@ -35,6 +35,8 @@
 
 using namespace fltk;
 
+int windows_charset = -1; // the default encoding; for non-unicode windows.  will be just -1 on other platforms.
+
 struct FontSize {float size; unsigned opengl_id;};
 
 // The public-visible fltk::Font structures are actually imbedded in
Index: src/scrollrect.cxx
===================================================================
--- src/scrollrect.cxx	(revision 6151)
+++ src/scrollrect.cxx	(working copy)
@@ -27,6 +27,7 @@
 #include <fltk/Window.h>
 #include <fltk/x.h>
 #include <fltk/draw.h>
+#include <fltk/run.h>
 
 // Turn this off to stop using copy-area for scrolling:
 #define USE_SCROLL 1
@@ -46,8 +47,6 @@
 
 #endif /* SYSRGN */
 
-extern int has_unicode();
-
 // Return true if rect is completely visible on screen.
 // If other window is overlapping rect, return false.
 static bool is_visible(int x, int y, int w, int h)
@@ -58,7 +57,7 @@
   // Copy system clipping region from fltk::dc
   GetRandomRgn (fltk::dc, rgn0, SYSRGN);
 
-  if (!has_unicode()) {
+  if (!fltk::has_unicode()) {
     // if not unicode then we are running on Win9x and the following applies:
     // Windows 9x operating systems the region is returned in window coordinates,
     // and on Windows XP/2k machines the region is in screen coordinates.. SIGH!
Index: src/x11/run.cxx
===================================================================
--- src/x11/run.cxx	(revision 6151)
+++ src/x11/run.cxx	(working copy)
@@ -2751,6 +2751,20 @@
   }
 }
 
+const char* fltk::os_name_family_id() { // some short name/id like Win98 WinNT OSX X11 etc.
+	return "X11";
+}
+
+const char* fltk::os_name_full() { // later this can be more elaborated version name
+	return os_name_family_id();
+}
+
+int fltk::has_unicode() // see run.h
+{
+	return 3; // good os - unicode
+	// TODO: detect really old, pre-unicode unixes?
+}
+
 //
 // End of "$Id$".
 //
Index: src/x11/Font.cxx
===================================================================
--- src/x11/Font.cxx	(revision 6151)
+++ src/x11/Font.cxx	(working copy)
@@ -3,3 +3,7 @@
 # else
 #  include "Font_xlfd.cxx"
 # endif
+
+int windows_charset = -1; // the default encoding; for non-unicode windows.  will be just -1 on other platforms.
+
+
Index: fltk/run.h
===================================================================
--- fltk/run.h	(revision 6151)
+++ fltk/run.h	(working copy)
@@ -85,6 +85,11 @@
 FL_API void* thread_message();
 FL_API bool in_main_thread();
 
+// some other OS-information
+FL_API const char* os_name_family_id(); // some short name/id like winNT winXP MACOSX etc.
+FL_API const char* os_name_full(); // later this can be more elaborated version name
+FL_API int has_unicode(); // 0==no(win95 etc) 1==yes(reserved for win98+unicows) 2==yes(winXP etc) 3==yes(good os)
+
 }
 
 #endif
Index: fltk/Font.h
===================================================================
--- fltk/Font.h	(revision 6151)
+++ fltk/Font.h	(working copy)
@@ -65,6 +65,8 @@
 // Find and return every font on the system.
 FL_API int list_fonts(Font**& arrayp);
 
+extern int windows_charset; // the default encoding; for non-unicode windows.  will be just -1 on other platforms.
+
 }
 
 #endif
Index: fltk/FL_VERSION.h
===================================================================
--- fltk/FL_VERSION.h	(revision 6151)
+++ fltk/FL_VERSION.h	(working copy)
@@ -21,6 +21,7 @@
 # define FL_MINOR_VERSION 1 //!< The minor release number, 0-9
 # define FL_PATCH_VERSION 0 //!< The patch number, 0-999
 # define FL_VERSION	  2.1000
+# define FL_VERSION_EXTRA	  "+(LimCore unicode hacks v4)"
 
 #if defined(__cplusplus) || defined(DOXYGEN) /* Allow this file to be included by C code */
 #include "FL_API.h"

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to