summaryrefslogtreecommitdiff
path: root/test/unittest_text.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2009-04-12 13:48:03 +0000
committerMatthias Melcher <fltk@matthiasm.com>2009-04-12 13:48:03 +0000
commitafe1b90dd012216b007112dc5c92f22a1f034bd7 (patch)
tree4901f175dfc467c1fad640657e9f0db4f823c8d4 /test/unittest_text.cxx
parentfcfe41ee0566038fcc6c690569b4d04469f43b06 (diff)
Reorganized Unittest / fixed and improved OS X keybord support and alternative input methods / fixed OS X utf8 DnD
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6755 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'test/unittest_text.cxx')
-rw-r--r--test/unittest_text.cxx97
1 files changed, 97 insertions, 0 deletions
diff --git a/test/unittest_text.cxx b/test/unittest_text.cxx
new file mode 100644
index 000000000..231e22dbe
--- /dev/null
+++ b/test/unittest_text.cxx
@@ -0,0 +1,97 @@
+//
+// "$Id: $"
+//
+// Unit tests for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2009 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems on the following page:
+//
+// http://www.fltk.org/str.php
+//
+
+#include <FL/Fl_Box.H>
+#include <FL/fl_draw.H>
+
+//
+// --- fl_text_extents() tests -----------------------------------------------
+//
+class TextExtentsTest : public Fl_Widget
+{
+ void DrawTextAndBoxes(const char *txt, int X, int Y) {
+ int wo = 0, ho = 0;
+ int dx, dy;
+ // First, we draw the bounding boxes (fl_measure and fl_text_extents)
+ // draw fl_measure() typographical bounding box
+ fl_measure(txt, wo, ho, 0);
+ int desc = fl_descent();
+ fl_color(FL_RED);
+ fl_rect(X, Y-ho+desc, wo, ho);
+ // draw fl_text_extents() glyph bounding box
+ fl_text_extents(txt, dx, dy, wo, ho);
+ fl_color(FL_GREEN);
+ fl_rect(X+dx, Y+dy, wo, ho);
+ // Then we draw the text to show how it fits insode each of the two boxes
+ fl_color(FL_BLACK);
+ fl_draw(txt, X, Y);
+ }
+public:
+ static Fl_Widget *create() {
+ return new TextExtentsTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
+ }
+ TextExtentsTest(int x, int y, int w, int h) : Fl_Widget(x, y, w, h) {}
+ void draw(void) {
+ int x0 = x(); // origin is current window position for Fl_Box
+ int y0 = y();
+ int w0 = w();
+ int h0 = h();
+ fl_push_clip(x0, y0, w0, h0); // reset local clipping
+ {
+ // set the background colour - slightly off-white to enhance the green bounding box
+ fl_color(fl_gray_ramp(FL_NUM_GRAY - 3));
+ fl_rectf(x0, y0, w0, h0);
+
+ fl_font(FL_HELVETICA, 30);
+ int xx = x0+55;
+ int yy = y0+40;
+ DrawTextAndBoxes("!abcdeABCDE\"#A", xx, yy); yy += 50; // mixed string
+ DrawTextAndBoxes("oacs", xx, yy); xx += 100; // small glyphs
+ DrawTextAndBoxes("qjgIPT", xx, yy); yy += 50; xx -= 100; // glyphs with descenders
+ DrawTextAndBoxes("````````", xx, yy); yy += 50; // high small glyphs
+ DrawTextAndBoxes("--------", xx, yy); yy += 50; // mid small glyphs
+ DrawTextAndBoxes("________", xx, yy); yy += 50; // low small glyphs
+
+ fl_font(FL_HELVETICA, 14);
+ fl_color(FL_RED); fl_draw("fl_measure bounding box in RED", xx, yy); yy += 20;
+ fl_color(FL_GREEN); fl_draw("fl_text_extents bounding box in GREEN", xx, yy);
+ fl_color(FL_BLACK);
+ xx = x0 + 10; yy += 30;
+ fl_draw("NOTE: On systems with text anti-aliasing (e.g. OSX Quartz)", xx, yy);
+ w0 = h0 = 0; fl_measure("NOTE: ", w0, h0, 0);
+ xx += w0; yy += h0;
+ fl_draw("text may leak slightly outside the fl_text_extents()", xx, yy);
+ }
+ fl_pop_clip(); // remove the local clip
+ }
+};
+
+UnitTest textExtents("rendering text", TextExtentsTest::create);
+
+//
+// End of "$Id: $"
+//