1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
/*
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
*
* Copyright © 2009-2011 Operational Dynamics Consulting, Pty Ltd
*
* The code in this file, and the program it is a part of, is made available
* to you by its authors as open source software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License version
* 2 ("GPL") as published by the Free Software Foundation.
*
* This program 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 GPL for more details.
*
* You should have received a copy of the GPL along with this program. If not,
* see http://www.gnu.org/licenses/. The authors of this program may be
* contacted through http://java-gnome.sourceforge.net/.
*/
package textview;
import org.gnome.gdk.Event;
import org.gnome.gtk.Gtk;
import org.gnome.gtk.TextBuffer;
import org.gnome.gtk.TextIter;
import org.gnome.gtk.TextTag;
import org.gnome.gtk.TextView;
import org.gnome.gtk.Widget;
import org.gnome.gtk.Window;
import org.gnome.gtk.WrapMode;
import org.gnome.pango.FontDescription;
import org.gnome.pango.Style;
/**
* Are all the characters in the rendered text the same height? Not all fonts
* behave in this regard.
*
* <p>
* Run this as:
*
* <pre>
* $ java -client -ea -classpath tmp/gtk-4.0.jar:tmp/tests textview.ExampleFontHeight 10
* </pre>
*
* to see the 10pt problem on buggy distros like Ubuntu.
*
* @author Andrew Cowie
*/
public final class ExampleFontHeights
{
private ExampleFontHeights(int pt) {
final Window w;
final TextView view;
final FontDescription desc;
final TextBuffer buffer;
final TextTag filename, function, classname;
TextIter pointer;
w = new Window();
view = new TextView();
desc = new FontDescription("DejaVu Serif, " + pt);
view.overrideFont(desc);
buffer = new TextBuffer();
filename = new TextTag();
filename.setFamily("DejaVu Sans Mono, " + pt);
filename.setStyle(Style.ITALIC);
filename.setForeground("darkgreen");
function = new TextTag();
function.setFamily("DejaVu Sans Mono, " + pt);
classname = new TextTag();
classname.setFamily("DejaVu Sans, " + pt);
classname.setForeground("darkblue");
pointer = buffer.getIterStart();
buffer.insert(pointer, "Accessing the ");
buffer.insert(pointer, "/tmp", filename);
buffer.insert(pointer, " directory directly is fine, but the ");
buffer.insert(pointer, "File", classname);
buffer.insert(pointer, " class has a ");
buffer.insert(pointer, "createTempFile()", function);
buffer.insert(pointer, " function that you are often better off using.");
view.setBuffer(buffer);
view.setWrapMode(WrapMode.WORD);
view.setSizeRequest(250, -1);
w.add(view);
w.setTitle("DejaVu " + pt + "pt");
w.showAll();
w.connect(new Window.DeleteEvent() {
public boolean onDeleteEvent(Widget source, Event event) {
Gtk.mainQuit();
return false;
}
});
}
public static void main(String[] args) {
final int pt;
Gtk.init(args);
if (args.length == 1) {
pt = Integer.parseInt(args[0]);
} else {
pt = 11;
}
new ExampleFontHeights(pt);
Gtk.main();
}
}
|