Debian Codegraph @

test/unittest_symbol.cxx

raw symbols SCIP
1 //
2 // Unit tests for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2022 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16
17 #include "unittests.h"
18
19 #include <FL/Fl_Box.H>
20 #include <FL/fl_draw.H>
21
22 //
23 // Test symbol rendering
24 //
25 class Ut_Symbol_Test : public Fl_Widget
26 {
27 void draw_text_and_boxes(const char *txt, int X, int Y) {
28 int wo = 0, ho = 0;
29 fl_measure(txt, wo, ho, 1);
30 // Draw fl_measure() rect
31 fl_color(FL_RED);
32 fl_rect(X, Y, wo, ho);
33 // //////////////////////////////////////////////////////////////////////
34 // NOTE: fl_text_extents() currently does not support multiline strings..
35 // until it does, let's leave this out, as we do multiline tests..
36 // //////////////////////////////////////////////////////////////////////
37 // // draw fl_text_extents() glyph bounding box
38 // int dx,dy;
39 // fl_text_extents(txt, dx, dy, wo, ho);
40 // fl_color(FL_GREEN);
41 // fl_rect(X+dx, Y+dy, wo, ho);
42 //
43 // Draw text with symbols enabled
44 fl_color(FL_BLACK);
45 fl_draw(txt, X, Y, 10, 10, FL_ALIGN_INSIDE|FL_ALIGN_TOP|FL_ALIGN_LEFT, 0, 1);
46 }
47 public:
48 static Fl_Widget *create() {
49 return new Ut_Symbol_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
50 }
51 Ut_Symbol_Test(int x, int y, int w, int h)
52 : Fl_Widget(x, y, w, h) {
53 }
54 void draw(void) FL_OVERRIDE {
55 int x0 = x(); // origin is current window position for Fl_Box
56 int y0 = y();
57 int w0 = w();
58 int h0 = h();
59 fl_push_clip(x0, y0, w0, h0); // reset local clipping
60 {
61 // set the background colour - slightly off-white to enhance the green bounding box
62 fl_color(fl_gray_ramp(FL_NUM_GRAY - 3));
63 fl_rectf(x0, y0, w0, h0);
64 int fsize = 25;
65 fl_font(FL_HELVETICA, fsize);
66 int xx = x0+10;
67 int yy = y0+10;
68 draw_text_and_boxes("Text" ,xx,yy); yy += fsize+10; // check no symbols
69 draw_text_and_boxes("@->" ,xx,yy); yy += fsize+10; // check symbol alone
70 draw_text_and_boxes("@-> " ,xx,yy); yy += fsize+10; // check symbol with trailing space
71 draw_text_and_boxes("@-> Rt Arrow" ,xx,yy); yy += fsize+10; // check symbol at left edge
72 draw_text_and_boxes("Lt Arrow @<-" ,xx,yy); yy += fsize+10; // check symbol at right edge
73 draw_text_and_boxes("@-> Rt/Lt @<-" ,xx,yy); yy += fsize+10; // check symbol at lt+rt edges
74 draw_text_and_boxes("@@ At/Lt @<-" ,xx,yy); yy += fsize+10; // check @@ at left, symbol at right
75 draw_text_and_boxes("@-> Lt/At @@" ,xx,yy); yy += fsize+10; // check symbol at left, @@ at right
76 draw_text_and_boxes("@@ At/At @@" ,xx,yy); yy += fsize+10; // check @@ at left+right
77 xx = x0+200;
78 yy = y0+10;
79 draw_text_and_boxes("Line1\nLine2" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, no symbol
80 draw_text_and_boxes("@-> Line1\nLine2 @<-" ,xx,yy); yy += (fsize+10)*2; // check 2 lines, lt+rt symbols
81 draw_text_and_boxes("@-> Line1\nLine2\nLine3 @<-",xx,yy); yy += (fsize+10)*3; // check 3 lines, lt+rt symbols
82 draw_text_and_boxes("@@@@" ,xx,yy); yy += (fsize+10); // check abutting @@'s
83 draw_text_and_boxes("@@ @@" ,xx,yy); yy += (fsize+10); // check @@'s with space sep
84
85 fl_font(FL_HELVETICA, 14);
86 fl_color(FL_RED);
87 fl_draw("fl_measure bounding box in RED", x0+10,y0+h0-20);
88 }
89 fl_pop_clip(); // remove the local clip
90 }
91 };
92
93 UnitTest symbolExtents(UT_TEST_SYBOL, "Symbol Text", Ut_Symbol_Test::create);