2008-09-11 03:56:49 +04:00
|
|
|
//
|
|
|
|
// UTF-8 test program for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2016-01-31 07:33:54 +03:00
|
|
|
// Copyright 1998-2016 by Bill Spitzak and others.
|
2008-09-11 03:56:49 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2008-09-11 03:56:49 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2010-04-28 07:15:47 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2008-09-11 03:56:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Double_Window.H>
|
|
|
|
#include <FL/Fl_Scroll.H>
|
|
|
|
#include <FL/Fl_Choice.H>
|
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
2011-01-01 22:34:14 +03:00
|
|
|
#include <FL/Fl_Tile.H>
|
2008-09-11 03:56:49 +04:00
|
|
|
#include <FL/Fl_Hold_Browser.H>
|
|
|
|
#include <FL/Fl_Value_Output.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Check_Button.H>
|
|
|
|
#include <FL/Fl_Output.H>
|
|
|
|
#include <FL/fl_draw.H>
|
2008-09-19 21:40:20 +04:00
|
|
|
#include <FL/fl_utf8.h>
|
2022-01-16 21:02:36 +03:00
|
|
|
#include <FL/fl_string_functions.h>
|
2008-09-11 03:56:49 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
//
|
|
|
|
// Font chooser widget for the Fast Light Tool Kit(FLTK).
|
|
|
|
//
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
#define DEF_SIZE 16 // default value for the font size picker
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
static Fl_Double_Window *fnt_chooser_win;
|
|
|
|
static Fl_Hold_Browser *fontobj;
|
|
|
|
static Fl_Hold_Browser *sizeobj;
|
|
|
|
|
|
|
|
static Fl_Value_Output *fnt_cnt;
|
|
|
|
static Fl_Button *refresh_btn;
|
|
|
|
static Fl_Button *choose_btn;
|
|
|
|
static Fl_Output *fix_prop;
|
|
|
|
static Fl_Check_Button *own_face;
|
|
|
|
|
|
|
|
static int **sizes = NULL;
|
|
|
|
static int *numsizes = NULL;
|
|
|
|
static int pickedsize = DEF_SIZE;
|
|
|
|
static char label[1000];
|
|
|
|
|
|
|
|
static Fl_Double_Window *main_win;
|
|
|
|
static Fl_Scroll *thescroll;
|
|
|
|
static Fl_Font extra_font;
|
|
|
|
|
|
|
|
static int font_count = 0;
|
|
|
|
static int first_free = 0;
|
|
|
|
|
2011-05-01 16:24:22 +04:00
|
|
|
static void cb_exit(Fl_Button*, void*) {
|
|
|
|
if(fnt_chooser_win) fnt_chooser_win->hide();
|
|
|
|
if(main_win) main_win->hide();
|
|
|
|
} /* cb_exit */
|
2011-01-01 21:57:37 +03:00
|
|
|
|
|
|
|
/*
|
2011-01-02 17:54:20 +03:00
|
|
|
Class for displaying sample fonts.
|
2011-01-01 21:57:37 +03:00
|
|
|
*/
|
2008-09-11 03:56:49 +04:00
|
|
|
class FontDisplay : public Fl_Widget
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
void draw(void);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
public:
|
2011-01-01 21:57:37 +03:00
|
|
|
int font, size;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
int test_fixed_pitch(void);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
FontDisplay(Fl_Boxtype B, int X, int Y, int W, int H, const char *L = 0)
|
2011-01-01 22:04:26 +03:00
|
|
|
: Fl_Widget(X, Y, W, H, L)
|
2011-01-01 21:57:37 +03:00
|
|
|
{
|
|
|
|
box(B);
|
|
|
|
font = 0;
|
|
|
|
size = DEF_SIZE;
|
|
|
|
}
|
2008-09-11 03:56:49 +04:00
|
|
|
};
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
Draw the sample text.
|
|
|
|
*/
|
2008-09-11 03:56:49 +04:00
|
|
|
void FontDisplay::draw(void)
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
draw_box();
|
|
|
|
fl_font((Fl_Font)font, size);
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_draw(label(), x() + 3, y() + 3, w() - 6, h() - 6, align());
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
int FontDisplay::test_fixed_pitch(void)
|
|
|
|
{
|
|
|
|
int w1, w2;
|
|
|
|
int h1, h2;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
w1 = w2 = 0;
|
|
|
|
h1 = h2 = 0;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
fl_font((Fl_Font)font, size);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
fl_measure("MHMHWWMHMHMHM###WWX__--HUW", w1, h1, 0);
|
|
|
|
fl_measure("iiiiiiiiiiiiiiiiiiiiiiiiii", w2, h2, 0);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
if (w1 == w2) return 1; // exact match - fixed pitch
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// 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...
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
return 0; // NOT fixed pitch
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
static FontDisplay *textobj;
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
static void size_cb(Fl_Widget *, long)
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
int size_idx = sizeobj->value();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
if (!size_idx) return;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
const char *c = sizeobj->text(size_idx);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
while (*c < '0' || *c > '9') c++; // find the first numeric char
|
|
|
|
pickedsize = atoi(c); // convert the number string to a value
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// Now set the font view to the selected size and redraw it.
|
|
|
|
textobj->size = pickedsize;
|
|
|
|
textobj->redraw();
|
|
|
|
}
|
2008-09-11 03:56:49 +04:00
|
|
|
|
|
|
|
|
|
|
|
static void font_cb(Fl_Widget *, long)
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
int font_idx = fontobj->value() + first_free;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
if (!font_idx) return;
|
|
|
|
font_idx--;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
textobj->font = font_idx;
|
|
|
|
sizeobj->clear();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
int size_count = numsizes[font_idx-first_free];
|
|
|
|
int *size_array = sizes[font_idx-first_free];
|
|
|
|
if (!size_count)
|
|
|
|
{
|
|
|
|
// no preferred sizes - probably TT fonts etc...
|
|
|
|
}
|
|
|
|
else if (size_array[0] == 0)
|
|
|
|
{
|
|
|
|
// many sizes, probably a scaleable font with preferred sizes
|
|
|
|
int j = 1;
|
|
|
|
for (int i = 1; i <= 64 || i < size_array[size_count - 1]; i++)
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
if (j < size_count && i == size_array[j])
|
|
|
|
{
|
2022-09-26 17:12:18 +03:00
|
|
|
snprintf(buf, 16, "@b%d", i);
|
2011-01-01 21:57:37 +03:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
else
|
2022-09-26 17:12:18 +03:00
|
|
|
snprintf(buf, 16, "%d", i);
|
2011-01-01 21:57:37 +03:00
|
|
|
sizeobj->add(buf);
|
|
|
|
}
|
|
|
|
sizeobj->value(pickedsize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// some sizes, probably a font with a few fixed sizes available
|
|
|
|
int w = 0;
|
|
|
|
for (int i = 0; i < size_count; i++)
|
|
|
|
{
|
|
|
|
// find the nearest available size to the current picked size
|
|
|
|
if (size_array[i] <= pickedsize) w = i;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
char buf[16];
|
2022-09-26 17:12:18 +03:00
|
|
|
snprintf(buf, 16, "@b%d", size_array[i]);
|
2011-01-01 21:57:37 +03:00
|
|
|
sizeobj->add(buf);
|
|
|
|
}
|
|
|
|
sizeobj->value(w + 1);
|
|
|
|
}
|
|
|
|
size_cb(sizeobj, 0); // force selection of nearest valid size, then redraw
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
if (looks_fixed > 1)
|
|
|
|
fix_prop->value("near");
|
|
|
|
else
|
|
|
|
fix_prop->value("fixed");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fix_prop->value("prop");
|
|
|
|
}
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
static void choose_cb(Fl_Widget *, long)
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
int font_idx = fontobj->value() + first_free;
|
|
|
|
if (!font_idx)
|
|
|
|
{
|
|
|
|
puts("No font chosen");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int font_type;
|
|
|
|
font_idx -= 1;
|
|
|
|
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));
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
Fl::set_font(extra_font, (Fl_Font)font_idx);
|
2020-07-01 19:03:10 +03:00
|
|
|
// Fl::set_font(extra_font, Fl::get_font((Fl_Font)font_idx));
|
2011-01-01 21:57:37 +03:00
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
int size_idx = sizeobj->value();
|
|
|
|
if (!size_idx)
|
|
|
|
{
|
|
|
|
puts("No size selected");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
printf("size %d\n\n", pickedsize);
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
fflush(stdout);
|
|
|
|
main_win->redraw();
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
2011-01-01 21:57:37 +03:00
|
|
|
|
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
static void refresh_cb(Fl_Widget *, long)
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
main_win->redraw();
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
static void own_face_cb(Fl_Widget *, void *)
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
int font_idx;
|
|
|
|
int cursor_restore = 0;
|
|
|
|
static int i_was = -1; // used to keep track of where we were in the list...
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
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();
|
2020-07-01 19:03:10 +03:00
|
|
|
// Populating the font widget can be slower than an old dog with three legs
|
2011-01-01 21:57:37 +03:00
|
|
|
// on a bad day, show a wait cursor
|
|
|
|
fnt_chooser_win->cursor(FL_CURSOR_WAIT);
|
|
|
|
cursor_restore = 1;
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// 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];
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
if(own_face->value() == 0) {
|
|
|
|
char *p = buffer;
|
2011-01-01 22:04:26 +03:00
|
|
|
// if the font is BOLD, set the bold attribute in the list
|
2020-07-01 19:03:10 +03:00
|
|
|
if (font_type & FL_BOLD) {
|
2011-01-01 21:57:37 +03:00
|
|
|
*p++ = '@';
|
|
|
|
*p++ = 'b';
|
|
|
|
}
|
|
|
|
if (font_type & FL_ITALIC) { // ditto for italic fonts
|
|
|
|
*p++ = '@';
|
|
|
|
*p++ = 'i';
|
|
|
|
}
|
|
|
|
// Suppress subsequent formatting - some MS fonts have '@' in their name
|
|
|
|
*p++ = '@';
|
|
|
|
*p++ = '.';
|
|
|
|
strcpy(p, name);
|
2020-07-01 19:03:10 +03:00
|
|
|
} else {
|
2011-01-01 22:04:26 +03:00
|
|
|
// Show font in its own face
|
2020-07-01 19:03:10 +03:00
|
|
|
// this is neat, but really slow on some systems:
|
2011-01-01 22:04:26 +03:00
|
|
|
// uses each font to display its own name
|
2022-09-26 17:12:18 +03:00
|
|
|
snprintf (buffer, sizeof(buffer), "@F%d@.%s", font_idx, name);
|
2011-01-01 21:57:37 +03:00
|
|
|
}
|
|
|
|
fontobj->add(buffer);
|
|
|
|
}
|
|
|
|
// now put the browser position back the way it was... more or less
|
|
|
|
fontobj->topline(i_was);
|
|
|
|
// restore the cursor
|
|
|
|
if(cursor_restore) fnt_chooser_win->cursor(FL_CURSOR_DEFAULT);
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
static void create_font_widget()
|
|
|
|
{
|
2011-01-01 22:34:14 +03:00
|
|
|
// Create the font sample label
|
2011-01-01 21:57:37 +03:00
|
|
|
strcpy(label, "Font Sample\n");
|
|
|
|
int i = 12; // strlen(label);
|
|
|
|
int n = 0;
|
|
|
|
ulong c;
|
|
|
|
for (c = ' '+1; c < 127; c++) {
|
|
|
|
if (!(c&0x1f)) label[i++]='\n';
|
2021-08-31 18:49:31 +03:00
|
|
|
if (c == '@') label[i++] = '@';
|
|
|
|
label[i++] = (char)c;
|
2011-01-01 21:57:37 +03:00
|
|
|
}
|
|
|
|
label[i++] = '\n';
|
|
|
|
for (c = 0xA1; c < 0x600; c += 9) {
|
|
|
|
if (!(++n&(0x1f))) label[i++]='\n';
|
|
|
|
i += fl_utf8encode((unsigned int)c, label + i);
|
|
|
|
}
|
|
|
|
label[i] = 0;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
// Create the window layout
|
|
|
|
fnt_chooser_win = new Fl_Double_Window(380, 420, "Font Selector");
|
|
|
|
{
|
|
|
|
Fl_Tile *tile = new Fl_Tile(0, 0, 380, 420);
|
|
|
|
{
|
|
|
|
Fl_Group *textgroup = new Fl_Group(0, 0, 380, 105);
|
|
|
|
{
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
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);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
textgroup->box(FL_FLAT_BOX);
|
|
|
|
textgroup->resizable(textobj);
|
|
|
|
textgroup->end();
|
2020-07-01 19:03:10 +03:00
|
|
|
}
|
2011-01-01 22:34:14 +03:00
|
|
|
Fl_Group *fontgroup = new Fl_Group(0, 105, 380, 315);
|
2020-07-01 19:03:10 +03:00
|
|
|
{
|
2011-01-01 22:34:14 +03:00
|
|
|
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);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
sizeobj = new Fl_Hold_Browser(310, 110, 60, 270);
|
|
|
|
sizeobj->box(FL_FRAME_BOX);
|
|
|
|
sizeobj->color(53, 3);
|
|
|
|
sizeobj->callback(size_cb);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
// Create the status bar
|
|
|
|
Fl_Group *stat_bar = new Fl_Group (10, 385, 380, 30);
|
2020-07-01 19:03:10 +03:00
|
|
|
{
|
2011-01-01 22:34:14 +03:00
|
|
|
fnt_cnt = new Fl_Value_Output(10, 390, 40, 20);
|
|
|
|
fnt_cnt->label("fonts");
|
|
|
|
fnt_cnt->align(FL_ALIGN_RIGHT);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
fix_prop = new Fl_Output(100, 390, 40, 20);
|
|
|
|
fix_prop->color(FL_BACKGROUND_COLOR);
|
|
|
|
fix_prop->value("prop");
|
|
|
|
fix_prop->clear_visible_focus();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
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");
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
Fl_Box * dummy = new Fl_Box(220, 390, 1, 1);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
choose_btn = new Fl_Button(240, 385, 60, 30);
|
|
|
|
choose_btn->label("Select");
|
|
|
|
choose_btn->callback(choose_cb);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
refresh_btn = new Fl_Button(310, 385, 60, 30);
|
|
|
|
refresh_btn->label("Refresh");
|
|
|
|
refresh_btn->callback(refresh_cb);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
stat_bar->resizable (dummy);
|
|
|
|
stat_bar->end();
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 22:34:14 +03:00
|
|
|
fontgroup->box(FL_FLAT_BOX);
|
|
|
|
fontgroup->resizable(fontobj);
|
|
|
|
fontgroup->end();
|
|
|
|
}
|
|
|
|
tile->end();
|
|
|
|
}
|
|
|
|
fnt_chooser_win->resizable(tile);
|
|
|
|
fnt_chooser_win->end();
|
2020-07-01 19:03:10 +03:00
|
|
|
fnt_chooser_win->callback((Fl_Callback*)cb_exit);
|
2011-01-01 22:34:14 +03:00
|
|
|
}
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
int make_font_chooser(void)
|
|
|
|
{
|
2011-01-01 21:57:37 +03:00
|
|
|
int font_idx;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// create the widget frame
|
|
|
|
create_font_widget();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// Load the systems available fonts - ask for everything
|
2020-07-01 19:03:10 +03:00
|
|
|
// font_count = Fl::set_fonts("*");
|
2018-02-09 17:39:42 +03:00
|
|
|
#ifdef _WIN32
|
2011-01-01 21:57:37 +03:00
|
|
|
font_count = Fl::set_fonts("*");
|
2016-01-31 07:33:54 +03:00
|
|
|
#elif defined(__APPLE__)
|
2011-01-01 21:57:37 +03:00
|
|
|
font_count = Fl::set_fonts("*");
|
2008-09-11 03:56:49 +04:00
|
|
|
#else
|
2020-07-01 19:03:10 +03:00
|
|
|
// Load the systems available fonts - ask for everything that claims to be
|
2011-01-01 22:04:26 +03:00
|
|
|
// iso10646 compatible
|
2011-01-01 21:57:37 +03:00
|
|
|
font_count = Fl::set_fonts("-*-*-*-*-*-*-*-*-*-*-*-*-iso10646-1");
|
2008-09-11 03:56:49 +04:00
|
|
|
#endif
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
// allocate space for the sizes and numsizes array, now we know how many
|
2011-01-01 22:04:26 +03:00
|
|
|
// entries it needs
|
2011-01-01 21:57:37 +03:00
|
|
|
sizes = new int*[font_count];
|
|
|
|
numsizes = new int[font_count];
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// 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++)
|
|
|
|
{
|
|
|
|
// Find out how many sizes are supported for each font face
|
|
|
|
int *size_array;
|
|
|
|
int size_count = Fl::get_font_sizes((Fl_Font)font_idx, size_array);
|
|
|
|
numsizes[font_idx-first_free] = size_count;
|
2011-01-01 22:04:26 +03:00
|
|
|
// if the font has multiple sizes, populate the 2-D sizes array
|
|
|
|
if (size_count)
|
2011-01-01 21:57:37 +03:00
|
|
|
{
|
|
|
|
sizes[font_idx-first_free] = new int[size_count];
|
|
|
|
for (int j = 0; j < size_count; j++)
|
|
|
|
sizes[font_idx-first_free][j] = size_array[j];
|
|
|
|
}
|
|
|
|
} // end of font list filling loop
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// Call this once to get the font browser loaded up
|
|
|
|
own_face_cb(NULL, 0);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
fontobj->value(1);
|
2011-01-01 22:34:14 +03:00
|
|
|
// optional hard-coded font for testing - do not use!
|
2020-07-01 19:03:10 +03:00
|
|
|
// fontobj->textfont(261);
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
font_cb(fontobj, 0);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
fnt_cnt->value(font_count);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
return font_count;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
} // make_font_chooser
|
|
|
|
|
|
|
|
/* End of Font Chooser Widget code */
|
2011-01-01 21:57:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
/* Unicode Font display widget */
|
|
|
|
|
|
|
|
void box_cb(Fl_Widget* o, void*) {
|
|
|
|
thescroll->box(((Fl_Button*)o)->value() ? FL_DOWN_FRAME : FL_NO_BOX);
|
|
|
|
thescroll->redraw();
|
|
|
|
}
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
class right_left_input : public Fl_Input
|
|
|
|
{
|
|
|
|
public:
|
2021-08-27 15:52:43 +03:00
|
|
|
right_left_input (int x, int y, int w, int h) : Fl_Input(x, y, w, h) {}
|
2011-01-01 21:57:37 +03:00
|
|
|
void draw() {
|
|
|
|
if (type() == FL_HIDDEN_INPUT) return;
|
|
|
|
Fl_Boxtype b = box();
|
|
|
|
if (damage() & FL_DAMAGE_ALL) draw_box(b, color());
|
|
|
|
drawtext(x()+Fl::box_dx(b)+3, y()+Fl::box_dy(b),
|
|
|
|
w()-Fl::box_dw(b)-6, h()-Fl::box_dh(b));
|
|
|
|
}
|
|
|
|
void drawtext(int X, int Y, int W, int H) {
|
|
|
|
fl_color(textcolor());
|
|
|
|
fl_font(textfont(), textsize());
|
2021-08-31 18:49:31 +03:00
|
|
|
fl_rtl_draw(value(), (int)strlen(value()),
|
|
|
|
X + W, Y + fl_height() - fl_descent());
|
2011-01-01 21:57:37 +03:00
|
|
|
}
|
2008-09-11 03:56:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void i7_cb(Fl_Widget *w, void *d)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
char nb[] = "01234567";
|
|
|
|
Fl_Input *i7 = (Fl_Input*)w;
|
|
|
|
Fl_Input *i8 = (Fl_Input*)d;
|
|
|
|
static char buf[1024];
|
|
|
|
const char *ptr = i7->value();
|
|
|
|
while (ptr && *ptr) {
|
2011-01-01 21:57:37 +03:00
|
|
|
if (*ptr < ' ' || *ptr > 126) {
|
|
|
|
buf[i++] = '\\';
|
|
|
|
buf[i++] = nb[((*ptr >> 6) & 0x3)];
|
|
|
|
buf[i++] = nb[((*ptr >> 3) & 0x7)];
|
|
|
|
buf[i++] = nb[(*ptr & 0x7)];
|
|
|
|
} else {
|
|
|
|
if (*ptr == '\\') buf[i++] = '\\';
|
|
|
|
buf[i++] = *ptr;
|
|
|
|
}
|
|
|
|
ptr++;
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
buf[i] = 0;
|
|
|
|
i8->value(buf);
|
|
|
|
}
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2009-04-12 17:48:03 +04:00
|
|
|
class UCharDropBox : public Fl_Output {
|
|
|
|
public:
|
|
|
|
UCharDropBox(int x, int y, int w, int h, const char *label=0) :
|
2011-01-01 21:57:37 +03:00
|
|
|
Fl_Output(x, y, w, h, label) { }
|
2009-04-12 17:48:03 +04:00
|
|
|
int handle(int event) {
|
|
|
|
switch (event) {
|
|
|
|
case FL_DND_ENTER: return 1;
|
|
|
|
case FL_DND_DRAG: return 1;
|
|
|
|
case FL_DND_RELEASE: return 1;
|
|
|
|
case FL_PASTE:
|
2011-01-01 21:57:37 +03:00
|
|
|
{
|
|
|
|
static const char lut[] = "0123456789abcdef";
|
|
|
|
const char *t = Fl::event_text();
|
|
|
|
int i, n;
|
|
|
|
unsigned int ucode = fl_utf8decode(t, t+Fl::event_length(), &n);
|
|
|
|
if (n==0) {
|
|
|
|
value("");
|
|
|
|
return 1;
|
2009-04-12 17:48:03 +04:00
|
|
|
}
|
2011-01-01 21:57:37 +03:00
|
|
|
char buffer[200], *d = buffer;
|
|
|
|
for (i=0; i<n; i++) *d++ = t[i];
|
|
|
|
*d++ = ' ';
|
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
*d++ = '\\'; *d++ = 'x';
|
|
|
|
*d++ = lut[(t[i]>>4)&0x0f]; *d++ = lut[t[i]&0x0f];
|
|
|
|
}
|
|
|
|
*d++ = ' ';
|
|
|
|
*d++ = '0';
|
|
|
|
*d++ = 'x';
|
|
|
|
*d++ = lut[(ucode>>20)&0x0f]; *d++ = lut[(ucode>>16)&0x0f];
|
|
|
|
*d++ = lut[(ucode>>12)&0x0f]; *d++ = lut[(ucode>>8)&0x0f];
|
|
|
|
*d++ = lut[(ucode>>4)&0x0f]; *d++ = lut[ucode&0x0f];
|
|
|
|
*d++ = 0;
|
|
|
|
value(buffer);
|
|
|
|
}
|
2009-04-12 17:48:03 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return Fl_Output::handle(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2021-05-26 23:05:16 +03:00
|
|
|
const char *latin1 = // "ABCabcàèéïâîöüã123"
|
|
|
|
"\x41\x42\x43\x61\x62\x63\xe0\xe8\xe9\xef\xe2\xee\xf6\xfc\xe3\x31\x32\x33";
|
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
char *utf8 = (char*) malloc(strlen(latin1) * 5 + 1);
|
2021-08-31 18:49:31 +03:00
|
|
|
int l = fl_utf8froma(utf8, (unsigned int)strlen(latin1) * 5 + 1,
|
|
|
|
latin1, (unsigned int)strlen(latin1));
|
2011-01-01 21:57:37 +03:00
|
|
|
make_font_chooser();
|
|
|
|
extra_font = FL_TIMES_BOLD_ITALIC;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
/* setup the extra font */
|
|
|
|
Fl::set_font(extra_font,
|
2018-02-09 17:39:42 +03:00
|
|
|
#ifdef _WIN32
|
2011-01-01 21:57:37 +03:00
|
|
|
" Arial Unicode MS"
|
2016-01-31 07:33:54 +03:00
|
|
|
#elif defined(__APPLE__)
|
2011-01-01 21:57:37 +03:00
|
|
|
"Monaco"
|
2008-09-11 03:56:49 +04:00
|
|
|
#else
|
2011-01-01 21:57:37 +03:00
|
|
|
"-*-*-*-*-*-*-*-*-*-*-*-*-iso10646-1"
|
2008-09-11 03:56:49 +04:00
|
|
|
#endif
|
2011-01-01 21:57:37 +03:00
|
|
|
);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
main_win = new Fl_Double_Window (200 + 5*75, 400, "Unicode Display Test");
|
|
|
|
main_win->begin();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
Fl_Input i1(5, 5, 190, 25);
|
|
|
|
utf8[l] = '\0';
|
|
|
|
i1.value(utf8);
|
|
|
|
Fl_Scroll scroll(200,0,5 * 75,400);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
int off = 2;
|
2011-05-01 16:24:22 +04:00
|
|
|
int end_list = 0x10000 / 16;
|
2008-09-11 03:56:49 +04:00
|
|
|
if (argc > 1) {
|
2011-01-01 21:57:37 +03:00
|
|
|
off = (int)strtoul(argv[1], NULL, 0);
|
2011-05-01 16:24:22 +04:00
|
|
|
end_list = off + 0x10000;
|
2011-01-01 21:57:37 +03:00
|
|
|
off /= 16;
|
2011-05-01 16:24:22 +04:00
|
|
|
end_list /= 16;
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
argc = 1;
|
2011-05-01 16:24:22 +04:00
|
|
|
for (long y = off; y < end_list; y++) {
|
2008-09-11 03:56:49 +04:00
|
|
|
int o = 0;
|
2011-05-01 16:24:22 +04:00
|
|
|
char bu[25]; // index label
|
|
|
|
char buf[16 * 6]; // utf8 text
|
2008-09-11 03:56:49 +04:00
|
|
|
int i = 16 * y;
|
2011-05-01 16:24:22 +04:00
|
|
|
for (int x = 0; x < 16; x++) {
|
2011-01-01 21:57:37 +03:00
|
|
|
int l;
|
|
|
|
l = fl_utf8encode(i, buf + o);
|
|
|
|
if (l < 1) l = 1;
|
|
|
|
o += l;
|
|
|
|
i++;
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
buf[o] = '\0';
|
2022-09-26 17:12:18 +03:00
|
|
|
snprintf(bu, sizeof(bu), "0x%06lX", y * 16);
|
2011-05-01 16:24:22 +04:00
|
|
|
Fl_Input *b = new Fl_Input(200,(y-off)*25,80,25);
|
|
|
|
b->textfont(FL_COURIER);
|
2020-07-22 06:15:41 +03:00
|
|
|
b->value(fl_strdup(bu));
|
2011-05-01 16:24:22 +04:00
|
|
|
b = new Fl_Input(280,(y-off)*25,380,25);
|
2008-09-11 03:56:49 +04:00
|
|
|
b->textfont(extra_font);
|
2020-07-22 06:15:41 +03:00
|
|
|
b->value(fl_strdup(buf));
|
2008-09-11 03:56:49 +04:00
|
|
|
}
|
|
|
|
scroll.end();
|
2011-05-01 16:24:22 +04:00
|
|
|
main_win->resizable(scroll);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
thescroll = &scroll;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
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);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
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);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-01-30 00:55:23 +03:00
|
|
|
const char *ltr_txt = "\\->e\xCC\x82=\xC3\xAA";
|
2008-09-11 03:56:49 +04:00
|
|
|
Fl_Input i4(5, 90, 190, 25);
|
|
|
|
i4.value(ltr_txt);
|
|
|
|
i4.textfont(extra_font);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
wchar_t r_to_l_txt[] = {/*8238,*/
|
2011-01-01 22:04:26 +03:00
|
|
|
1610, 1608, 1606, 1604, 1603, 1608, 1583, 0};
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
char abuf[40];
|
2011-01-01 21:57:37 +03:00
|
|
|
// l = fl_unicode2utf(r_to_l_txt, 8, abuf);
|
2008-09-11 03:56:49 +04:00
|
|
|
l = fl_utf8fromwc(abuf, 40, r_to_l_txt, 8);
|
|
|
|
abuf[l] = 0;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
right_left_input i5(5, 115, 190, 50);
|
|
|
|
i5.textfont(extra_font);
|
|
|
|
i5.textsize(30);
|
|
|
|
i5.value(abuf);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
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);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
wchar_t r_to_l_txt1[] = { /*8238,*/
|
|
|
|
1610, 0x20, 1608, 0x20, 1606, 0x20,
|
2011-01-01 22:04:26 +03:00
|
|
|
1604, 0x20, 1603, 0x20, 1608, 0x20, 1583, 0};
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-01-01 21:57:37 +03:00
|
|
|
// l = fl_unicode2utf(r_to_l_txt1, 14, abuf);
|
2008-09-11 03:56:49 +04:00
|
|
|
l = fl_utf8fromwc(abuf, 40, r_to_l_txt1, 14);
|
|
|
|
abuf[l] = 0;
|
|
|
|
right_left_input i6(5, 175, 190, 50);
|
|
|
|
i6.textfont(extra_font);
|
|
|
|
i6.textsize(30);
|
|
|
|
i6.value(abuf);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
// Now try Greg Ercolano's Japanese test sequence
|
2011-01-02 17:54:20 +03:00
|
|
|
// SOME JAPANESE UTF-8 TEXT
|
2020-07-01 19:03:10 +03:00
|
|
|
const char *utfstr =
|
2011-01-01 22:34:14 +03:00
|
|
|
"\xe4\xbd\x95\xe3\x82\x82\xe8\xa1"
|
2020-07-01 19:03:10 +03:00
|
|
|
"\x8c\xe3\x82\x8b\xe3\x80\x82";
|
|
|
|
|
2009-04-12 17:48:03 +04:00
|
|
|
UCharDropBox db(5, 300, 190, 30);
|
|
|
|
db.textsize(16);
|
|
|
|
db.value("unichar drop box");
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
Fl_Output o9(5, 330, 190, 45);
|
|
|
|
o9.textfont(extra_font);
|
|
|
|
o9.textsize(30);
|
|
|
|
o9.value(utfstr);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
main_win->end();
|
2011-05-01 16:24:22 +04:00
|
|
|
main_win->callback((Fl_Callback*)cb_exit);
|
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
fl_set_status(0, 370, 100, 30);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
main_win->show(argc,argv);
|
2011-05-01 16:24:22 +04:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
fnt_chooser_win->show();
|
2011-05-01 16:24:22 +04:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
int ret = Fl::run();
|
2011-05-01 16:24:22 +04:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
// Free up the sizes arrays we allocated
|
|
|
|
if(numsizes) {delete [] numsizes;}
|
|
|
|
if(sizes) {delete [] sizes;}
|
2011-05-01 16:24:22 +04:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
return ret;
|
|
|
|
}
|