mirror of
https://github.com/fltk/fltk.git
synced 2026-05-30 04:55:29 +08:00
Modified ut8 test program formatting to get closer to FLTK coding standards
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8160 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+40
-25
@@ -47,10 +47,10 @@
|
|||||||
// Font chooser widget for the Fast Light Tool Kit(FLTK).
|
// Font chooser widget for the Fast Light Tool Kit(FLTK).
|
||||||
//
|
//
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
#define DEF_SIZE 16 // default value for the font size picker
|
#define DEF_SIZE 16 // default value for the font size picker
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
static Fl_Double_Window *fnt_chooser_win;
|
static Fl_Double_Window *fnt_chooser_win;
|
||||||
static Fl_Hold_Browser *fontobj;
|
static Fl_Hold_Browser *fontobj;
|
||||||
static Fl_Hold_Browser *sizeobj;
|
static Fl_Hold_Browser *sizeobj;
|
||||||
@@ -73,7 +73,10 @@ static Fl_Font extra_font;
|
|||||||
static int font_count = 0;
|
static int font_count = 0;
|
||||||
static int first_free = 0;
|
static int first_free = 0;
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
|
/*
|
||||||
|
Class for displaying samle fonts.
|
||||||
|
*/
|
||||||
class FontDisplay : public Fl_Widget
|
class FontDisplay : public Fl_Widget
|
||||||
{
|
{
|
||||||
void draw(void);
|
void draw(void);
|
||||||
@@ -91,7 +94,10 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
|
/*
|
||||||
|
Draw the sample text.
|
||||||
|
*/
|
||||||
void FontDisplay::draw(void)
|
void FontDisplay::draw(void)
|
||||||
{
|
{
|
||||||
draw_box();
|
draw_box();
|
||||||
@@ -99,7 +105,8 @@ void FontDisplay::draw(void)
|
|||||||
fl_color(FL_BLACK);
|
fl_color(FL_BLACK);
|
||||||
fl_draw(label(), x() + 3, y() + 3, w() - 6, h() - 6, align());
|
fl_draw(label(), x() + 3, y() + 3, w() - 6, h() - 6, align());
|
||||||
}
|
}
|
||||||
/********************************************************************************************/
|
|
||||||
|
|
||||||
int FontDisplay::test_fixed_pitch(void)
|
int FontDisplay::test_fixed_pitch(void)
|
||||||
{
|
{
|
||||||
int w1, w2;
|
int w1, w2;
|
||||||
@@ -124,10 +131,10 @@ int FontDisplay::test_fixed_pitch(void)
|
|||||||
return 0; // NOT fixed pitch
|
return 0; // NOT fixed pitch
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
static FontDisplay *textobj;
|
static FontDisplay *textobj;
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
static void size_cb(Fl_Widget *, long)
|
static void size_cb(Fl_Widget *, long)
|
||||||
{
|
{
|
||||||
int size_idx = sizeobj->value();
|
int size_idx = sizeobj->value();
|
||||||
@@ -143,7 +150,8 @@ static void size_cb(Fl_Widget *, long)
|
|||||||
textobj->size = pickedsize;
|
textobj->size = pickedsize;
|
||||||
textobj->redraw();
|
textobj->redraw();
|
||||||
}
|
}
|
||||||
/********************************************************************************************/
|
|
||||||
|
|
||||||
static void font_cb(Fl_Widget *, long)
|
static void font_cb(Fl_Widget *, long)
|
||||||
{
|
{
|
||||||
int font_idx = fontobj->value() + first_free;
|
int font_idx = fontobj->value() + first_free;
|
||||||
@@ -210,7 +218,7 @@ static void font_cb(Fl_Widget *, long)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
static void choose_cb(Fl_Widget *, long)
|
static void choose_cb(Fl_Widget *, long)
|
||||||
{
|
{
|
||||||
int font_idx = fontobj->value() + first_free;
|
int font_idx = fontobj->value() + first_free;
|
||||||
@@ -227,7 +235,7 @@ static void choose_cb(Fl_Widget *, long)
|
|||||||
printf("FLTK name :%s:\n", Fl::get_font((Fl_Font)font_idx));
|
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_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();
|
int size_idx = sizeobj->value();
|
||||||
@@ -247,13 +255,14 @@ static void choose_cb(Fl_Widget *, long)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
main_win->redraw();
|
main_win->redraw();
|
||||||
}
|
}
|
||||||
/********************************************************************************************/
|
|
||||||
|
|
||||||
static void refresh_cb(Fl_Widget *, long)
|
static void refresh_cb(Fl_Widget *, long)
|
||||||
{
|
{
|
||||||
main_win->redraw();
|
main_win->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
static void own_face_cb(Fl_Widget *, void *)
|
static void own_face_cb(Fl_Widget *, void *)
|
||||||
{
|
{
|
||||||
int font_idx;
|
int font_idx;
|
||||||
@@ -305,7 +314,7 @@ static void own_face_cb(Fl_Widget *, void *)
|
|||||||
if(cursor_restore) fnt_chooser_win->cursor(FL_CURSOR_DEFAULT);
|
if(cursor_restore) fnt_chooser_win->cursor(FL_CURSOR_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
static void create_font_widget()
|
static void create_font_widget()
|
||||||
{
|
{
|
||||||
fnt_chooser_win = new Fl_Double_Window(380, 420, "Font Selector");
|
fnt_chooser_win = new Fl_Double_Window(380, 420, "Font Selector");
|
||||||
@@ -320,8 +329,10 @@ static void create_font_widget()
|
|||||||
label[i++]=c;
|
label[i++]=c;
|
||||||
}
|
}
|
||||||
label[i++] = '\n';
|
label[i++] = '\n';
|
||||||
for (c = 0xA1; c < 0x600; c += 9) {if (!(++n&(0x1f))) label[i++]='\n';
|
for (c = 0xA1; c < 0x600; c += 9) {
|
||||||
i += fl_utf8encode((unsigned int)c, label + i);}
|
if (!(++n&(0x1f))) label[i++]='\n';
|
||||||
|
i += fl_utf8encode((unsigned int)c, label + i);
|
||||||
|
}
|
||||||
label[i] = 0;
|
label[i] = 0;
|
||||||
|
|
||||||
textobj = new FontDisplay(FL_FRAME_BOX, 10, 10, 360, 90, label);
|
textobj = new FontDisplay(FL_FRAME_BOX, 10, 10, 360, 90, label);
|
||||||
@@ -339,7 +350,7 @@ static void create_font_widget()
|
|||||||
sizeobj->color(53, 3);
|
sizeobj->color(53, 3);
|
||||||
sizeobj->callback(size_cb);
|
sizeobj->callback(size_cb);
|
||||||
|
|
||||||
// Create the status bar
|
// Create the status bar
|
||||||
Fl_Group * stat_bar = new Fl_Group (10, 385, 380, 30);
|
Fl_Group * stat_bar = new Fl_Group (10, 385, 380, 30);
|
||||||
stat_bar->begin();
|
stat_bar->begin();
|
||||||
|
|
||||||
@@ -375,7 +386,7 @@ static void create_font_widget()
|
|||||||
fnt_chooser_win->end();
|
fnt_chooser_win->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
int make_font_chooser(void)
|
int make_font_chooser(void)
|
||||||
{
|
{
|
||||||
int font_idx;
|
int font_idx;
|
||||||
@@ -384,7 +395,7 @@ int make_font_chooser(void)
|
|||||||
create_font_widget();
|
create_font_widget();
|
||||||
|
|
||||||
// Load the systems available fonts - ask for everything
|
// Load the systems available fonts - ask for everything
|
||||||
// font_count = Fl::set_fonts("*");
|
// font_count = Fl::set_fonts("*");
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
font_count = Fl::set_fonts("*");
|
font_count = Fl::set_fonts("*");
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
@@ -418,7 +429,7 @@ int make_font_chooser(void)
|
|||||||
own_face_cb(NULL, 0);
|
own_face_cb(NULL, 0);
|
||||||
|
|
||||||
fontobj->value(1);
|
fontobj->value(1);
|
||||||
// fontobj->textfont(261); // optional hard-coded font for testing - do not use!
|
// fontobj->textfont(261); // optional hard-coded font for testing - do not use!
|
||||||
|
|
||||||
font_cb(fontobj, 0);
|
font_cb(fontobj, 0);
|
||||||
|
|
||||||
@@ -429,7 +440,9 @@ int make_font_chooser(void)
|
|||||||
} // make_font_chooser
|
} // make_font_chooser
|
||||||
|
|
||||||
/* End of Font Chooser Widget code */
|
/* End of Font Chooser Widget code */
|
||||||
/********************************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/* Unicode Font display widget */
|
/* Unicode Font display widget */
|
||||||
|
|
||||||
void box_cb(Fl_Widget* o, void*) {
|
void box_cb(Fl_Widget* o, void*) {
|
||||||
@@ -437,6 +450,7 @@ void box_cb(Fl_Widget* o, void*) {
|
|||||||
thescroll->redraw();
|
thescroll->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class right_left_input : public Fl_Input
|
class right_left_input : public Fl_Input
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -481,6 +495,7 @@ void i7_cb(Fl_Widget *w, void *d)
|
|||||||
i8->value(buf);
|
i8->value(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class UCharDropBox : public Fl_Output {
|
class UCharDropBox : public Fl_Output {
|
||||||
public:
|
public:
|
||||||
UCharDropBox(int x, int y, int w, int h, const char *label=0) :
|
UCharDropBox(int x, int y, int w, int h, const char *label=0) :
|
||||||
@@ -522,18 +537,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/********************************************************************************************/
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
/* If this file is saved as a UTF-8, the latin1 text in the comment
|
/* If this file is saved as a UTF-8, the latin1 text in the comment
|
||||||
* below doesn't look right any more!
|
* below doesn't look right any more!
|
||||||
* Store the specific latin-1 byte values here... this should be equivalent to:
|
* Store the specific latin-1 byte values here... this should be equivalent to:
|
||||||
* char *latin1 = "ABCabcàèéïâîöüã123"; */
|
* char *latin1 = "ABCabcàèéïâîöüã123"; */
|
||||||
const char *latin1 = "\x41\x42\x43\x61\x62\x63\xe0\xe8\xe9\xef\xe2\xee\xf6\xfc\xe3\x31\x32\x33";
|
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);
|
char *utf8 = (char*) malloc(strlen(latin1) * 5 + 1);
|
||||||
l = 0;
|
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));
|
l = fl_utf8froma(utf8, (strlen(latin1) * 5 + 1), latin1, strlen(latin1));
|
||||||
|
|
||||||
make_font_chooser();
|
make_font_chooser();
|
||||||
@@ -609,7 +624,7 @@ int main(int argc, char** argv)
|
|||||||
wchar_t r_to_l_txt[] ={/*8238,*/ 1610, 1608, 1606, 1604, 1603, 1608, 1583, 0};
|
wchar_t r_to_l_txt[] ={/*8238,*/ 1610, 1608, 1606, 1604, 1603, 1608, 1583, 0};
|
||||||
|
|
||||||
char abuf[40];
|
char abuf[40];
|
||||||
// l = fl_unicode2utf(r_to_l_txt, 8, abuf);
|
// l = fl_unicode2utf(r_to_l_txt, 8, abuf);
|
||||||
l = fl_utf8fromwc(abuf, 40, r_to_l_txt, 8);
|
l = fl_utf8fromwc(abuf, 40, r_to_l_txt, 8);
|
||||||
abuf[l] = 0;
|
abuf[l] = 0;
|
||||||
|
|
||||||
@@ -627,7 +642,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
wchar_t r_to_l_txt1[] ={/*8238,*/ 1610, 0x20, 1608, 0x20, 1606, 0x20, 1604, 0x20, 1603, 0x20, 1608, 0x20, 1583, 0};
|
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_unicode2utf(r_to_l_txt1, 14, abuf);
|
||||||
l = fl_utf8fromwc(abuf, 40, r_to_l_txt1, 14);
|
l = fl_utf8fromwc(abuf, 40, r_to_l_txt1, 14);
|
||||||
abuf[l] = 0;
|
abuf[l] = 0;
|
||||||
right_left_input i6(5, 175, 190, 50);
|
right_left_input i6(5, 175, 190, 50);
|
||||||
|
|||||||
Reference in New Issue
Block a user