DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2378
Version: 1.3.0
Link: http://www.fltk.org/str.php?L2378
Version: 1.3.0
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Table.H>
#include <FL/fl_draw.H>
#include <FL/fl_ask.H>
#include <FL/Fl_PostScript.H>
#include <FL/Fl_Choice.H>
class MyTable : public Fl_Table {
public:
int offset;
static void event_callback(Fl_Widget*, void*);
MyTable(int x, int y, int w, int h, const char *l) : Fl_Table(x,y,w,h,l)
{
callback(&event_callback, (void*)this);
when(FL_WHEN_RELEASE);
};
void draw_cell(TableContext tc, int r, int c, int x, int y, int w, int h);
};
Fl_Choice *choice;
Fl_Window *window;
Fl_Box *bottom_box;
Fl_Box *lang_box;
MyTable *table1, *table2, *table3, *table4;
static int extra_table[] = { // additional unicode characters we handle
0x192/*florin*/, 0x2C6/*circumflex*/, 0x2C7/*caron*/,
0x2D8/*breve*/, 0x2D9/*dotaccent*/, 0x2DA/*ring*/, 0x2DB/*ogonek*/,
0x2DC/*tilde*/, 0x2DD/*hungarumlaut*/,
0x2013/*endash*/, 0x2014/*emdash*/, 0x2018/*quoteleft*/,
0x2019/*quoteright*/,
0x201A/*quotesinglbase*/, 0x201C/*quotedblleft*/, 0x201D/*quotedblright*/,
0x201E/*quotedblbase*/,
0x2020/*dagger*/, 0x2021/*daggerdbl*/, 0x2022/*bullet*/,
0x2026/*ellipsis*/, 0x2030/*perthousand*/, 0x2039/*guilsinglleft*/,
0x203A/*guilsinglright*/,
0x2044/*fraction*/, 0x20AC/*Euro*/, 0x2122/*trademark*/,
0x2202/*partialdiff*/, 0x2206/*Delta*/, 0x2211/*summation*/,
0x221A/*radical*/,
0x221E/*infinity*/, 0x2260/*notequal*/, 0x2264/*lessequal*/,
0x2265/*greaterequal*/,
0x25CA/*lozenge*/, 0xFB01/*fi*/, 0xFB02/*fl*/,
0xF8FF/*apple*/,
};
const int table_size = sizeof(extra_table)/sizeof(int);
void MyTable::event_callback(Fl_Widget*, void *data)
{
int l, utf = ' ';
char s[10];
static char buffer[50];
MyTable *table = (MyTable*)data;
int R = table->callback_row();
int C = table->callback_col();
if (R >= 0 && C >= 0 && Fl::event() == FL_PUSH) {
if(table == table4) {
int rank = R + C * 0x10;
if (rank < table_size) utf = extra_table[rank];
else return;
}
else {
utf = table->offset + R + C * 0x10;
}
l = fl_utf8encode(utf, s);
s[l] = 0;
sprintf(buffer, "U+%4.4X %s",utf, s);
bottom_box->label(buffer);
bottom_box->labelsize(22);
bottom_box->redraw();
}
}
void MyTable::draw_cell(TableContext context, int R, int C, int X, int Y, int
W, int H)
{
switch ( context )
{
case CONTEXT_STARTPAGE: // Fl_Table telling us it's starting to
draw page
fl_font(choice->value(), 14);
return;
case CONTEXT_CELL: // Fl_Table telling us to draw cells
fl_push_clip(X, Y, W, H);
{
// BG COLOR
fl_color(FL_WHITE);
fl_rectf(X, Y, W, H);
// TEXT
char s[10];
unsigned utf = 0xBF; // reverse question mark
if(this == table4) {
int rank = R + C * 0x10;
if (rank < table_size) utf = extra_table[rank];
else utf = ' ';
}
else {
utf = offset + R + C * 0x10;
}
int l = fl_utf8encode(utf, s);
s[l] = 0;
fl_color(FL_BLACK);
fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER);
// BORDER
fl_color(FL_LIGHT2);
fl_rect(X, Y, W, H);
}
fl_pop_clip();
return;
default:
return;
}
}
void postscript(Fl_Widget *w, void *data)
{
Fl_PostScript_File_Device printer ;
if( printer.start_job(1, Fl_PostScript_Graphics_Driver::LETTER,
Fl_PostScript_Graphics_Driver::LANDSCAPE) == 0 ) {
printer.start_page();
printer.scale(0.95, .95);
printer.print_widget(window);
printer.end_page();
printer.end_job();
}
}
void choice_cb(Fl_Widget *w, void *data)
{
w->window()->redraw();
lang_box->labelfont(choice->value());
lang_box->redraw();
}
int main(void)
{
window = new Fl_Window(31*8*2 + 31*6 + 31*3 + 30, 25*16+60+60, "Examples of
text PostScript output");
Fl_Button *b = new Fl_Button(0,0,80, 20, "PostScript");
b->callback(postscript, NULL);
choice = new Fl_Choice(150, 0, 160, 20);
choice->add("FL_HELVETICA|FL_HELVETICA_BOLD|FL_HELVETICA_ITALIC|FL_HELVETICA_BOLD_ITALIC|"
"FL_COURIER|FL_COURIER_BOLD|FL_COURIER_ITALIC|FL_COURIER_BOLD_ITALIC|"
"FL_TIMES|FL_TIMES_BOLD|FL_TIMES_ITALIC|FL_TIMES_BOLD_ITALIC");
choice->value(0);
choice->callback(choice_cb, NULL);
choice->textsize(11);
table1 = new MyTable(0, 25, 31 * 8, window->h()-115, "ASCII");
table1->rows(16);
table1->cols(8);
table1->row_height_all(25);
table1->col_width_all(30);
table1->end();
table1->offset = 0x0;
table2 = new MyTable(31 * 8 + 10, 25, 31 * 6, window->h()-115, "Latin-1");
table2->rows(16);
table2->cols(6);
table2->row_height_all(25);
table2->col_width_all(30);
table2->end();
table2->offset = 0xA0;
table3 = new MyTable(2*(31 * 7 + 10), 25, 31 * 8, window->h()-115, "Latin
Extended-A");
table3->rows(16);
table3->cols(8);
table3->row_height_all(25);
table3->col_width_all(30);
table3->end();
table3->offset = 0x100;
table4 = new MyTable(table3->x()+table3->w(), 25, 31 * 3, window->h()-115,
"Misc.");
table4->rows(16);
table4->cols(3);
table4->row_height_all(25);
table4->col_width_all(30);
table4->end();
bottom_box = new Fl_Box(0, table1->y() + table1->h() , window->w(), 30,
"Click on cell to see the character's unicode value");
bottom_box->labelcolor(FL_RED);
lang_box = new Fl_Box(FL_FLAT_BOX,0 , bottom_box->y() + bottom_box->h() ,
window->w(), 60,
"СÑиле пообедаÑÑ Ð·Ð°Ð±Ð¾ÑиÑÑÑÑ
код Ñе, где он полÑгода ажиоÑажа.\n"
"Σε Ïλη μÎÏÎ¿Ï ÎÏÏελνε
γειÏονιάÏ. ÎÏ ÏÏÏήÏει ÏÏ
γγÏαÏήÏ");
lang_box->color(FL_WHITE);
lang_box->labelfont(choice->value());
window->end();
window->show();
Fl::run();
return 0;
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs