diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2020-07-01 18:03:10 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2020-07-06 20:28:20 +0200 |
| commit | f09e17c3c564e8310125a10c03397cbf473ff643 (patch) | |
| tree | 8d0fd4a28e3686c33aaa140d07ddba26ab28bdc2 /test/utf8.cxx | |
| parent | b0e0c355edaa2e23148cb0260ada907aec930f05 (diff) | |
Remove $Id$ tags, update URL's, and more
- remove obsolete svn '$Id$' tags from all source files
- update .fl files and generated files accordingly
- replace 'http://www.fltk.org' URL's with 'https://...'
- replace bug report URL 'str.php' with 'bugs.php'
- remove trailing whitespace
- fix other whitespace errors flagged by Git
- add and/or fix missing or wrong standard headers
- convert tabs to spaces in all source files
The only relevant code changes are in the fluid/ folder where
some .fl files and other source files were used to generate
the '$Id' headers and footers.
Diffstat (limited to 'test/utf8.cxx')
| -rw-r--r-- | test/utf8.cxx | 190 |
1 files changed, 92 insertions, 98 deletions
diff --git a/test/utf8.cxx b/test/utf8.cxx index 5dd9f57df..ed1dd1063 100644 --- a/test/utf8.cxx +++ b/test/utf8.cxx @@ -1,6 +1,4 @@ // -// "$Id$" -// // UTF-8 test program for the Fast Light Tool Kit (FLTK). // // Copyright 1998-2016 by Bill Spitzak and others. @@ -9,11 +7,11 @@ // the file "COPYING" which should have been included with this file. If this // file is missing or damaged, see the license at: // -// http://www.fltk.org/COPYING.php +// https://www.fltk.org/COPYING.php // -// Please report all bugs and problems on the following page: +// Please see the following page on how to report bugs and issues: // -// http://www.fltk.org/str.php +// https://www.fltk.org/bugs.php // #include <FL/Fl.H> @@ -77,13 +75,13 @@ static void cb_exit(Fl_Button*, void*) { class FontDisplay : public Fl_Widget { void draw(void); - + public: int font, size; - + int test_fixed_pitch(void); - - FontDisplay(Fl_Boxtype B, int X, int Y, int W, int H, const char *L = 0) + + FontDisplay(Fl_Boxtype B, int X, int Y, int W, int H, const char *L = 0) : Fl_Widget(X, Y, W, H, L) { box(B); @@ -109,23 +107,23 @@ int FontDisplay::test_fixed_pitch(void) { int w1, w2; int h1, h2; - + w1 = w2 = 0; h1 = h2 = 0; - + fl_font((Fl_Font)font, size); - + fl_measure("MHMHWWMHMHMHM###WWX__--HUW", w1, h1, 0); fl_measure("iiiiiiiiiiiiiiiiiiiiiiiiii", w2, h2, 0); - + if (w1 == w2) return 1; // exact match - fixed pitch - + // Is the font "nearly" fixed pitch? If it is within 5%, say it is... double f1 = (double)w1; double f2 = (double)w2; double delta = fabs(f1 - f2) * 5.0; if (delta <= f1) return 2; // nearly fixed pitch... - + return 0; // NOT fixed pitch } @@ -136,14 +134,14 @@ static FontDisplay *textobj; static void size_cb(Fl_Widget *, long) { int size_idx = sizeobj->value(); - + if (!size_idx) return; - + const char *c = sizeobj->text(size_idx); - + while (*c < '0' || *c > '9') c++; // find the first numeric char pickedsize = atoi(c); // convert the number string to a value - + // Now set the font view to the selected size and redraw it. textobj->size = pickedsize; textobj->redraw(); @@ -153,13 +151,13 @@ static void size_cb(Fl_Widget *, long) static void font_cb(Fl_Widget *, long) { int font_idx = fontobj->value() + first_free; - + if (!font_idx) return; font_idx--; - + textobj->font = font_idx; sizeobj->clear(); - + int size_count = numsizes[font_idx-first_free]; int *size_array = sizes[font_idx-first_free]; if (!size_count) @@ -192,7 +190,7 @@ static void font_cb(Fl_Widget *, long) { // find the nearest available size to the current picked size if (size_array[i] <= pickedsize) w = i; - + char buf[16]; sprintf(buf, "@b%d", size_array[i]); sizeobj->add(buf); @@ -200,7 +198,7 @@ static void font_cb(Fl_Widget *, long) sizeobj->value(w + 1); } size_cb(sizeobj, 0); // force selection of nearest valid size, then redraw - + // Now check to see if the font looks like a fixed pitch font or not... int looks_fixed = textobj->test_fixed_pitch(); if(looks_fixed) @@ -231,11 +229,11 @@ static void choose_cb(Fl_Widget *, long) const char *name = Fl::get_font_name((Fl_Font)font_idx, &font_type); printf("idx %d\nUser name :%s:\n", font_idx, name); printf("FLTK name :%s:\n", Fl::get_font((Fl_Font)font_idx)); - + Fl::set_font(extra_font, (Fl_Font)font_idx); - // Fl::set_font(extra_font, Fl::get_font((Fl_Font)font_idx)); + // Fl::set_font(extra_font, Fl::get_font((Fl_Font)font_idx)); } - + int size_idx = sizeobj->value(); if (!size_idx) { @@ -246,10 +244,10 @@ static void choose_cb(Fl_Widget *, long) const char *c = sizeobj->text(size_idx); while (*c < '0' || *c > '9') c++; // find the first numeric char int pickedsize = atoi(c); // convert the number string to a value - + printf("size %d\n\n", pickedsize); } - + fflush(stdout); main_win->redraw(); } @@ -266,30 +264,30 @@ static void own_face_cb(Fl_Widget *, void *) int font_idx; int cursor_restore = 0; static int i_was = -1; // used to keep track of where we were in the list... - + if (i_was < 0) { // not been here before i_was = 1; } else { i_was = fontobj->topline(); // record which was the topmost visible line fontobj->clear(); - // Populating the font widget can be slower than an old dog with three legs + // Populating the font widget can be slower than an old dog with three legs // on a bad day, show a wait cursor fnt_chooser_win->cursor(FL_CURSOR_WAIT); cursor_restore = 1; } - - + + // Populate the font list with the names of the fonts found for (font_idx = first_free; font_idx < font_count; font_idx++) { int font_type; const char *name = Fl::get_font_name((Fl_Font)font_idx, &font_type); char buffer[128]; - + if(own_face->value() == 0) { char *p = buffer; // if the font is BOLD, set the bold attribute in the list - if (font_type & FL_BOLD) { + if (font_type & FL_BOLD) { *p++ = '@'; *p++ = 'b'; } @@ -301,9 +299,9 @@ static void own_face_cb(Fl_Widget *, void *) *p++ = '@'; *p++ = '.'; strcpy(p, name); - } else { + } else { // Show font in its own face - // this is neat, but really slow on some systems: + // this is neat, but really slow on some systems: // uses each font to display its own name sprintf (buffer, "@F%d@.%s", font_idx, name); } @@ -334,7 +332,7 @@ static void create_font_widget() i += fl_utf8encode((unsigned int)c, label + i); } label[i] = 0; - + // Create the window layout fnt_chooser_win = new Fl_Double_Window(380, 420, "Font Selector"); { @@ -342,61 +340,61 @@ static void create_font_widget() { Fl_Group *textgroup = new Fl_Group(0, 0, 380, 105); { - + textobj = new FontDisplay(FL_FRAME_BOX, 10, 10, 360, 90, label); textobj->align(FL_ALIGN_TOP|FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); textobj->color(53, 3); - + textgroup->box(FL_FLAT_BOX); textgroup->resizable(textobj); textgroup->end(); - } + } Fl_Group *fontgroup = new Fl_Group(0, 105, 380, 315); - { + { fontobj = new Fl_Hold_Browser(10, 110, 290, 270); fontobj->box(FL_FRAME_BOX); fontobj->color(53, 3); fontobj->callback(font_cb); fnt_chooser_win->resizable(fontobj); - + sizeobj = new Fl_Hold_Browser(310, 110, 60, 270); sizeobj->box(FL_FRAME_BOX); sizeobj->color(53, 3); sizeobj->callback(size_cb); - + // Create the status bar Fl_Group *stat_bar = new Fl_Group (10, 385, 380, 30); - { + { fnt_cnt = new Fl_Value_Output(10, 390, 40, 20); fnt_cnt->label("fonts"); fnt_cnt->align(FL_ALIGN_RIGHT); - + fix_prop = new Fl_Output(100, 390, 40, 20); fix_prop->color(FL_BACKGROUND_COLOR); fix_prop->value("prop"); fix_prop->clear_visible_focus(); - + own_face = new Fl_Check_Button(150, 390, 40, 20, "Self"); own_face->value(0); own_face->type(FL_TOGGLE_BUTTON); own_face->clear_visible_focus(); own_face->callback(own_face_cb); own_face->tooltip("Display font names in their own face"); - + Fl_Box * dummy = new Fl_Box(220, 390, 1, 1); - + choose_btn = new Fl_Button(240, 385, 60, 30); choose_btn->label("Select"); choose_btn->callback(choose_cb); - + refresh_btn = new Fl_Button(310, 385, 60, 30); refresh_btn->label("Refresh"); refresh_btn->callback(refresh_cb); - + stat_bar->resizable (dummy); stat_bar->end(); } - + fontgroup->box(FL_FLAT_BOX); fontgroup->resizable(fontobj); fontgroup->end(); @@ -405,7 +403,7 @@ static void create_font_widget() } fnt_chooser_win->resizable(tile); fnt_chooser_win->end(); - fnt_chooser_win->callback((Fl_Callback*)cb_exit); + fnt_chooser_win->callback((Fl_Callback*)cb_exit); } } @@ -413,27 +411,27 @@ static void create_font_widget() int make_font_chooser(void) { int font_idx; - + // create the widget frame create_font_widget(); - + // Load the systems available fonts - ask for everything - // font_count = Fl::set_fonts("*"); + // font_count = Fl::set_fonts("*"); #ifdef _WIN32 font_count = Fl::set_fonts("*"); #elif defined(__APPLE__) font_count = Fl::set_fonts("*"); #else - // Load the systems available fonts - ask for everything that claims to be + // Load the systems available fonts - ask for everything that claims to be // iso10646 compatible font_count = Fl::set_fonts("-*-*-*-*-*-*-*-*-*-*-*-*-iso10646-1"); #endif - - // allocate space for the sizes and numsizes array, now we know how many + + // allocate space for the sizes and numsizes array, now we know how many // entries it needs sizes = new int*[font_count]; numsizes = new int[font_count]; - + // Populate the font list with the names of the fonts found first_free = FL_FREE_FONT; for (font_idx = first_free; font_idx < font_count; font_idx++) @@ -450,20 +448,20 @@ int make_font_chooser(void) sizes[font_idx-first_free][j] = size_array[j]; } } // end of font list filling loop - + // Call this once to get the font browser loaded up own_face_cb(NULL, 0); - + fontobj->value(1); // optional hard-coded font for testing - do not use! - // fontobj->textfont(261); - + // fontobj->textfont(261); + font_cb(fontobj, 0); - + fnt_cnt->value(font_count); - + return font_count; - + } // make_font_chooser /* End of Font Chooser Widget code */ @@ -568,16 +566,16 @@ public: int main(int argc, char** argv) { int l; - const char *latin1 = + const char *latin1 = "\x41\x42\x43\x61\x62\x63\xe0\xe8\xe9\xef\xe2\xee\xf6\xfc\xe3\x31\x32\x33"; char *utf8 = (char*) malloc(strlen(latin1) * 5 + 1); l = 0; - // l = fl_latin12utf((const unsigned char*)latin1, strlen(latin1), utf8); + // l = fl_latin12utf((const unsigned char*)latin1, strlen(latin1), utf8); l = fl_utf8froma(utf8, (strlen(latin1) * 5 + 1), latin1, strlen(latin1)); - + make_font_chooser(); extra_font = FL_TIMES_BOLD_ITALIC; - + /* setup the extra font */ Fl::set_font(extra_font, #ifdef _WIN32 @@ -588,15 +586,15 @@ int main(int argc, char** argv) "-*-*-*-*-*-*-*-*-*-*-*-*-iso10646-1" #endif ); - + main_win = new Fl_Double_Window (200 + 5*75, 400, "Unicode Display Test"); main_win->begin(); - + Fl_Input i1(5, 5, 190, 25); utf8[l] = '\0'; i1.value(utf8); Fl_Scroll scroll(200,0,5 * 75,400); - + int off = 2; int end_list = 0x10000 / 16; if (argc > 1) { @@ -629,50 +627,50 @@ int main(int argc, char** argv) } scroll.end(); main_win->resizable(scroll); - + thescroll = &scroll; - + char *utf8l = (char*) malloc(strlen(utf8) * 3 + 1); Fl_Input i2(5, 35, 190, 25); l = fl_utf_tolower((const unsigned char*)utf8, l, utf8l); utf8l[l] = '\0'; i2.value(utf8l); - + char *utf8u = (char*) malloc(strlen(utf8l) * 3 + 1); Fl_Input i3(5, 65, 190, 25); l = fl_utf_toupper((const unsigned char*)utf8l, l, utf8u); utf8u[l] = '\0'; i3.value(utf8u); - + const char *ltr_txt = "\\->e\xCC\x82=\xC3\xAA"; Fl_Input i4(5, 90, 190, 25); i4.value(ltr_txt); i4.textfont(extra_font); - - wchar_t r_to_l_txt[] = {/*8238,*/ + + wchar_t r_to_l_txt[] = {/*8238,*/ 1610, 1608, 1606, 1604, 1603, 1608, 1583, 0}; - + char abuf[40]; // l = fl_unicode2utf(r_to_l_txt, 8, abuf); l = fl_utf8fromwc(abuf, 40, r_to_l_txt, 8); abuf[l] = 0; - + right_left_input i5(5, 115, 190, 50); i5.textfont(extra_font); i5.textsize(30); i5.value(abuf); - + Fl_Input i7(5, 230, 190, 25); Fl_Input i8(5, 260, 190, 25); i7.callback(i7_cb, &i8); i7.textsize(20); i7.value(abuf); i7.when(FL_WHEN_CHANGED); - - wchar_t r_to_l_txt1[] = { /*8238,*/ - 1610, 0x20, 1608, 0x20, 1606, 0x20, + + wchar_t r_to_l_txt1[] = { /*8238,*/ + 1610, 0x20, 1608, 0x20, 1606, 0x20, 1604, 0x20, 1603, 0x20, 1608, 0x20, 1583, 0}; - + // l = fl_unicode2utf(r_to_l_txt1, 14, abuf); l = fl_utf8fromwc(abuf, 40, r_to_l_txt1, 14); abuf[l] = 0; @@ -680,27 +678,27 @@ int main(int argc, char** argv) i6.textfont(extra_font); i6.textsize(30); i6.value(abuf); - + // Now try Greg Ercolano's Japanese test sequence // SOME JAPANESE UTF-8 TEXT - const char *utfstr = + const char *utfstr = "\xe4\xbd\x95\xe3\x82\x82\xe8\xa1" - "\x8c\xe3\x82\x8b\xe3\x80\x82"; - + "\x8c\xe3\x82\x8b\xe3\x80\x82"; + UCharDropBox db(5, 300, 190, 30); db.textsize(16); db.value("unichar drop box"); - + Fl_Output o9(5, 330, 190, 45); o9.textfont(extra_font); o9.textsize(30); o9.value(utfstr); - + main_win->end(); main_win->callback((Fl_Callback*)cb_exit); fl_set_status(0, 370, 100, 30); - + main_win->show(argc,argv); fnt_chooser_win->show(); @@ -713,7 +711,3 @@ int main(int argc, char** argv) return ret; } - -// -// End of "$Id$". -// |
