[Top] | [Contents] | [Index] | [ ? ] |
1. Overview General information about GtkMathView. 2. Usage Compiling and installation instructions. 3. Interactivity Support 4. Sample Application 5. C++ Interface Summary of the C++ interface. 6. GTK+ Interface Summary of the GTK+ interface. 7. Tools Tools coming along the widget. 8. Bugs and Contributions How to report a bug.
-- The Detailed Node Listing ---
Usage
2.1 Download Where the source code is 2.2 Requirements Auxiliary packages to compile and run GtkMathView. 2.3 Installing How to compile the source code of the widget. 2.4 Compile and Link How to link against your source code. 2.5 Configuration How to fine-tune the widget
Configuration
2.5.1 Main Configuration File Basic configuration 2.5.2 Operator Dictionary Setting the default value for operator attributes 2.5.3 Font Setup How the widget maps Unicode characters into glyphs
Interactivity Support
3.1 Selection Highlighting sub-expressions 3.2 Point-and-click Functionalities Handling of basic mouse events 3.3 Editing Changind the source document tree
C++ Interface
5.1 Lengths About Lengths 5.2 Boxes and Rectangles 5.3 The MathMLRenderingEngine Class
Boxes and Rectangles
5.2.1 Rectangles 5.2.2 Bounding Boxes
Tools
7.1 mathmlviewer
A simple viewer application. 7.2 mathml2ps
A MathML => PostScript conversion utility.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For questions, comments, suggestions, bug reports, contributions, please contact the author at the following email address: luca.padovani@cs.unibo.it
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
2.1 Download Where the source code is 2.2 Requirements Auxiliary packages to compile and run GtkMathView. 2.3 Installing How to compile the source code of the widget. 2.4 Compile and Link How to link against your source code. 2.5 Configuration How to fine-tune the widget
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In the same page you will find unofficial RedHat packages and official Debian packages for the widget and related tools.
The source code is also available from the GNOME CVS repository, which can be
accesses anonymously via CVS at the following address
:pserver:anonymous@anoncvs.gnome.org:/cvs/gnome
The module name is gtkmathview
. The CVS repository can also be
browsed online at the address
http://cvs.gnome.org/lxr/source/gtkmathview/.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GTK+
(version 1.2) http://www.gtk.org, of course.
GMetaDOM
(at least version 0.1.5)
http://gmetadom.sourceforge.org. This library provides a C++ DOM
implementation based on Gdome2
http://gdome2.cs.unibo.it
which in turn is based on libxml
http://xmlsoft.org.
t1lib
(version 1.2 or higher)
ftp://sunsite.unc.edu/pub/Linux/libs/graphics/ This library is
not required, however, if you have it, you will be able to use Type1
fonts independently from the X font server. Furthermore, you will be
able to render anti-aliased text. This library is also needed in the
case you want to export MathML to PostScript. Note that the
configuration script is usually able to autodetect the library, if
installed, however you will have to configure some files and
environment variables. See the section about font installation below.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GMetaDOM
is
not installed. See the INSTALL file included in the source
distribution for detailed compilation and installation
instructions. After installation you will have the following files:
gtkmathview-config --cflags
to get compilation
flags of source files using the widget. Use gtkmathview-config
--libs
to get linking flags and libraries to be linked with your object
files.
configure
one of `--disable-static' or
`--disable-shared' you will find in this directory both static and shared
versions of the widget.
info -f /usr/local/info/gtkmathview.info
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To compile a source file which uses the widget use the command
gcc -c filename.c -l... -I... `gtkmathview-config --cflags`
The widget is compiled by default to generate both static and shared object file. It can be linked dynamically against your applications with the command:
gcc -o appname *.o `gtkmathview-config --libs`
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The widget can be partly configured after instantiation by using the
provided methods described in 6. GTK+ Interface. However, most of
the configuration is specified in an external file whose path can be
set in the environment variable MATHENGINECONF
. In case the
environment variable is not set, the widget will try to read the
configuration file from the default location, which typically is
/usr/local/share/gtkmathview
.
2.5.1 Main Configuration File Basic configuration 2.5.2 Operator Dictionary Setting the default value for operator attributes 2.5.3 Font Setup How the widget maps Unicode characters into glyphs
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The main configuration file is an XML document whose root element must
be math-engine-configuration
. The children of the root
element determine the value of a number of parameter that are
described below:
dictionary-path
: the content of this element is the
full path of the XML file describing the content of the operator
dictionary used by GtkMathView.
There can be more instances of the dictionary-path
element,
each pointing to a different dictionary. If an entry of the dictionary
is defined multiple times, possibly within different dictionaries, the
last definition is the one that matters. This way it is possible to
define the suggested operator dictionary as by the MathML
specification, and then customize it depending on the application
needs.
The format of the operator dictionary will be detailed in 2.5.2 Operator Dictionary.
font-configuration-path
: the content of this element
is the full path of the XML file describing the font configuration.
There are usually several instances of the
font-configuration-path
element.
The format of the font configuration file will be detailed in 2.5.3 Font Setup.
t1-config-path
: the content of this element is the
full path of the t1lib
font configuration file. The format of
this file is detailed in the t1lib
documentation and will not
be described here. Also, this entry is only necessary if the use of
Type~1 fonts is required.
font-size
: the attribute size
of this
element can be used to set the default value of font size used for
rendering the MathML document. The number must be followed by the
appropriate unit (typically points). For example, to set the default
font size to 12 points the size
attribute must be set to the
string 12pt
. The set of valid units is the same as the set of
units allowed in MathML documents; it is also described in
units. An application using GtkMathView can override the default
font size by invoking the gtk_math_view_set_font_size
method
which is described in 6. GTK+ Interface.
color
: default color of the rendered document. The
attributes foreground
and background
determine the
foreground and background colors respectively. The format of the two
attributes is the same as for color specifications on MathML elements
accepting the mathcolor
attribute. In particular, it is
possible to use one of the named colors defined by the HTML
specification, or to use an RGB format (a `#' sign followed by 3 or 6
hexadecimal digits).
link-color
: default color of tokens with an
xlink:href
attribute. The format of the two foreground
and background
attributes is the same as for the color
element.
select-color
: color combination used for selections.
The format of the two foreground
and background
attributes is the same as for the color
element.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The operator dictionary defines the default value of a number of
attributes that applies to mo
elements. The exact definition of
the operator dictionary along with the attributes that can be set is
described in the MathML specification(1)}
The dictionary XML file is made of a dictionary
element with an
arbitrary number of operator
children. For each operator the
following attributes can be used: name
(this is required),
form
(this is also required and can be one of prefix
,
infix
, or postfix
), fence
, separator
,
lspace
, rspace
, stretchy
, symmetric
,
maxsize
, minsize
, largeop
, movablelimits
,
accent
. The syntax for the attributes is the same as the one
specified in the MathML recommendation.
In addition, two extension attributes tspace
and bspace
can be defined. They represent the amount of space respectively at the
top and at the bottom of an operator. They are usually ignored, unless
the widget has been configured with the --enable-extensions
flag set.
A sample entry for the operator dictionary is the following,
describing the default attributes for an open parenthesis when it is
in prefix position (that is, the parenthesis is the first child of a
(possibly inferred) mrow
element):
<operator name="(" form="prefix" fence="true" stretchy="true" lspace="0em" rspace="0em"/> |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The font configuration XML file is made of a font-configuration
element with an arbitrary number of font
and map
children. font
children define how abstract font descriptions
are mapped into system font descriptions, whereas map
children
define an actual mapping of Unicode characters into glyph indexes for
a particular font. Every font
abstract description must
have a reference to a map
element. The reason why font
abstract descriptions and maps are kept separate is that many
different font abstract descriptions may share the same font map,
hence it is convenient to use an indirection instead of replicating
the map each time it is needed.
Each font
element has the following attributes:
Font Classification.
type
: type of the font. Currently x
(for X)
or ps
(for PostScript, Type1) fonts are supported.
mode
: mode for which the font should be used. May be
one of any
, text
, or math
.
mapping
: reference to the corresponding map
element. It can be an arbitrary non-empty string.
Font Description:
family
: the font family. This field is not fixed,
but the most common values are serif
, sans-serif
,
monospace
;
style
: either normal
or italic
;
weight
: either normal
or bold
;
size
: preferred size at which the font should be used.
If not specified the font will be magnified to the desired size.
Specific Font Data. The set of valid attributes depends on
the type
attribute. For X fonts, the attributes are
x-foundry
, x-family
, x-weight
, x-slant
,
x-width
, x-style
, x-pixels
, x-points
,
x-hres
, x-vres
, x-spacing
, x-avgwidth
,
x-registry
, x-encoding
. Their syntax follows the syntax
for X font specifications.
For PostScript (or Type1) fonts, the attributes are ps-name
and
ps-file
specifying the PostScript name of the font and the file
name that contains the font, respectively.
Each map
element has an id
attribute that font abstract
specifications can refer to and has an arbitrary list of
single
, range
, multi
, or stretchy
children. Whenever Unicode characters or glyph indexes need to be
referenced from the maps, they can be given in hexadecimal (with
0x
prefix), octal (with 0
prefix), or decimal (in all
the other cases). Unicode characters can also be specified by simply
inserting the character (or a character reference) into the attribute.
A single
child specifies the mapping for a single Unicode
character. The Unicode character is specified in the code
attribute, its index in the index
attribute.
A range
child specifies the mapping for a range of Unicode
characters. The first and last characters (inclusive) in the range are
specified in the first
and last
attributes,
respectively. The attribute offset
specifies the index of the
glyph corresponding to the first
character.
A multi
child specifies the mapping for a range of Unicode
characters whose glyph indexes do not follow the same order, or are
not all available. In this case the index
attribute is a space
separated list of glyph indexes, each related to the corresponding
Unicode character in the range. If there is no glyph corresponding to
a given Unicode character, the constant -1
must be used.
A stretchy
child specifies the mapping of a stretchable Unicode
character, that is a character that can be formatted in different
sizes, depending on the context. The code
attribute specifies
the Unicode character, and the direction
attribute specifies
whether the character can be stretched horizontally
(horizontal
), vertically (vertical
), or in both
directions (both
). A stretchy character has a mandatory
simple
child optionally followed by a compound
child.
The simple
child has an index
attribute that specifies
the glyph indexes (separated by spaces) corresponding to the character
as a whole, in increasing order of size. The compound
child has
an index
attribute that specifies the glyph indexes (separated
by spaces) corresponding to the dismantled pieces that can be combined
to build up the character. There must be 4 entries corresponding to
the leftmost (or bottommost) piece, the middle piece, the rightmost
(or topmost) piece, and the piece that can be repeated at will to make
the symbol as hight (or wide) as required.
For example, a specification like
<stretchy code="(" direction="vertical"> <simple index="0000 0020 0022 0040"/> <compound index="0060 -1 0100 0102"/> </stretchy> |
says that the open round parenthesis is available as simple
glyphs at the positions 0000
, 0020
, 0022
,
0040
. Those glyphs are listed in increasing order of size. In
case there is the need of an even bigger parenthesis, it can be
combined by using the 0060
glyph for the bottommost piece,
0100
glyph for the topmost piece, and 0102
as the glyph
that can be repeated at will.
A special note about True Type fonts: recent X servers can render a wide variety of fonts, including True Type fonts usually shipped with Microsoft Windows. These fonts have more flexible scaling capabilities and you could find the final rendering really improved by their use. Since their handling is almost completely hidden inside the X font server, the widget needs not any special configuration to use them, apart from a proper setting of the font configuration file (`font-configuration.xml').
Type1 fonts and the t1lib library: starting from version
0.2.0, the rendering engine can use the t1lib
library to render
Type1 fonts. It is known that t1lib
has some bugs that can
cause the widget to crash, especially in version 0.4.1 or later. Here
are some tips to configure the engine so that you can use Type1 fonts
(please, consult the t1lib
documentation at library's home page
for firther details).
First of all, you have to setup a little configuration file for the
t1lib
library. Call this file `t1.config' and place it
somewhere in your home directory. Here is a sample file (also
provided with the standard distribution):
# # ENCODING=. AFM=/usr/share/texmf/fonts/afm/ TYPE1=/usr/share/texmf/fonts/type1/bluesky/cm/:. |
In particular, you have to specify where your Type1 fonts reside
(TYPE1
) along with their metrics (AFM
). Metric
information in optional, since it can be (mostly) recovered from the
font file itself. However, metrics from the AFM
file can be
more precise than that automatically inferred. A sample configuration
file for t1lib
is included in the standard distribution of
gtkmathview
and is installed in
`/usr/local/share/gtkmathview/'.
Next, you have to setup an environment variable T1LIB_CONFIG
with the full path to this configuration file. For example, if you use
bash
:
export T1LIB_CONFIG=./config/t1.config
And, if you use tcsh
:
setenv T1LIB_CONFIG ./config/t1.config
Now you are ready to use Type1 fonts.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GtkMathView's support for interaction support can be summarized in three aspects, selection, point-and-click, and editing, which we will define more precisely in the sections that follows.
Interactivity support often implies re-rendering of the displayed
MathML document. As this can be an expensive operation, especially
when several actions take place in rapid succession, GtkMathView
provides for two methods (gtk_math_view_freeze
and
gtk_math_view_thaw
) that delay any re-computation and update of
the displaying window until the application has terminated the action.
As a matter of fact, due to the current design of GtkMathView's architecture, the use of these two methods is mandatory in that the displayed window is guaranteed to be updated correctly only if the two methods are properly used. Although we perceive this as a limitation, the points in favor are the following:
gtk_math_view_freeze
and
gtk_math_view_thaw
, as a way of improving performances;
It is safe to nest calls to gtk_math_view_freeze
and
gtk_math_view_thaw
methods at any level.
3.1 Selection Highlighting sub-expressions 3.2 Point-and-click Functionalities Handling of basic mouse events 3.3 Editing Changind the source document tree
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
By selection we mean the possibility for the user to distinguish one or more DOM elements from the others in a MathML document. The typical visual feedback for selected elements is that of displaying them with a different background color.
Selection support in GtkMathView consists of three methods and four signals. The methods are needed to set and query about the selection status of a particular MathML element, as this information is hidden within the internal data structures of GtkMathView and is not available as part of the MathML document itself. Selection is a boolean property: an element can be either selected or not, there are no multiple levels of selection.
Both gtk_math_view_select
and gtk_math_view_unselect
operate recursively on the given MathML element and also on all its
descendants, but the gtk_math_view_unselect
method can be used
to perforate a previously selected element thus leaving a "hole"
within a selection. This mechanism can be exploited for representing
patterns of elements within the MathML documents.
The signals related to selection are select_begin
,
select_end
, select_over
, and select_abort
. The
first three signals have two arguments, the MathML element on which
the signal has been emitted and the status of control keys on the
keyboard. The four signals are fired in disjoint sequences matching
the following regular expression:
select_begin select_over* (select_end | select_abort) |
which is to be read as follows: selection begins when the user presses
the first mouse button and moves it a bit from the original
position. As the user moves the mouse with the button pressed, an
arbitrary number of select_over
signals is emitted. Selection
can terminate in two cases: either the user releases the button
(select_end
) or he/she presses another mouse button, hence
aborting the selection (select_abort
).
An interface for which multiple selections are required can check the status of control keys on the keyboard in order to determine whether a new selection sequence replaces a previous selection or adds a new selection to it.
Support for semantic selection. The widget does not highlight
automatically the parts of the document on which the user is dragging
the mouse. It is complete responsibility of the application to handle
the selection signals and to invoke the gtk_math_view_select
method appropriately. Although this puts some burden on the
application side, it also enables the maximum flexibility, as
selection may be constrained in ways that, in the most general case,
are infeasible to hard code within GtkMathView.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Point-and-click is supported by the click
signal, which is
emitted when the users clicks on the MathML document. The two
arguments of the signal are the deepest MathML element on which the
mouse was placed at the time of the click or NULL
if there is
no such element, and the status of the control keys on the keyboard.
Among the possible usages for this signal are the activation of
hyperlinks and the management of maction
elements. When the
user clicks on the document, the event handler can look for a MathML
element that has a xlink:href
attribute set, and render that
document. The search is typically done by starting from the element
provided by the signal, and possibly climbing up the chain of elements
until one with the required attribute is found, or the root element is
reached, or any other application-specific condition applies.
Activation of maction
elements works in the same way. Currently
only the toggle
action is supported by GtkMathView. In
particular, once the maction
element is found, it is possible
to increase the number found in the selection
attribute, which
determines which of the maction
's children is displayed. If the
selection
is increased beyond the actual number of children,
GtkMathView will recast it into a valid range via a modulo
operation. This way the application code for handling maction
does not have to know the exact number of children, and is thus
simplified. Note however that this behavior is not mandated by the
MathML recommendation, and can differ in other MathML rendering
engines. Once the selection
attribute is set with the new
value, GtkMathView will recompute automatically the document's layout.
Possible conflicts in case the xlink:href
is set on an
maction
element must be resolved by the signal handler.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The notion of editing in the context of GtkMathView is very
limited. It simply refers to the fact that GtkMathView reacts
automatically as the source MathML document changes, but
GtkMathView itself does not enforce any constraints on how and when
the document can change. The management of maction
can be seen
as a very particular kind of editing, as it involves a modification of
the source document tree.
GtkMathView implements a number of internal mechanisms that try to optimize rendering, in the sense of minimizing the amount of computation that is needed to re-render a document after a modification has occurred.
Note also that in some cases local modifications may have non-local effects. For instance, modifying the content of a table cell may cause the re-computation of the whole table layout, as MathML attributes for table can specify constraints among cells in different columns or rows.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In this section we show a minimal GTK+ application that uses
GtkMathView for displaying a MathML document. The application is
intentionally small and only shows a small subset of GtkMathView
capabilities. More complex examples, including sophisticated
selections and maction
handling, can be found in the
GtkMathView source distribution.
The application begins, as usual, with some #include
directives
that load the necessary .h
files. Note in particular that the
gtkmathview.h
header file must be included in order to use the
widget.
#include <stdio.h> #include <gtk/gtk.h> #include <gtkmathview.h> |
Next we declare a number of global variables that represent the main
components of the graphical interface. The reason why these variables
are global is that we may need to reference them from outside the
main
function, where they are initialized.
static GtkWidget* window = NULL; static GtkWidget* main_vbox = NULL; static GtkWidget* main_area = NULL; static GtkWidget* scrolled_area = NULL; |
We also need two global variables to support selection:
static GdomeElement* first_selected = NULL; static GdomeElement* root_selected = NULL; |
The following is an auxiliary function that loads the MathML document
whose URI is specified in name
inside the widget.
static int load_document(const char* name) { GtkMathView* math_view = GTK_MATH_VIEW(main_area); g_return_val_if_fail(name != NULL, -1); g_return_val_if_fail(math_view != NULL, -1); return gtk_math_view_load_uri(math_view, name); } |
The click
function will be responsible for handling
click
signals as they are emitted. Note that the function takes
three arguments: the GtkMathView widget that has generated the signal
(math_view), the MathML element on which the user has clicked
(elem), and finally the status of control keys.
static void click(GtkMathView* math_view, GdomeElement* elem, gint state) { g_return_if_fail(math_view != NULL); printf("*** click signal: %p %x\n", elem, state); if (elem != NULL) { /* do something with the element */ } } |
The implementation of the selection mechanism is slightly more
complicated as it involves handling at least two different signals.
Upon receiving the select_begin
signal the current selection,
if present, is deleted, and the two global variables
first_selected
and root_selected
are initialized with
the element elem under the mouse pointer at the time selection
was initiated. The element, if not NULL
, is highlighted.
Note that the whole body of the signal handler begins with a
gtk_math_view_freeze
operation and ends with a
gtk_math_view_thaw
operation. This means that the display
window is not updated until the signal handler terminates, with two
advantages: the method is more efficient as GtkMathView updates
only once, after two operations have been completed, and also we avoid
the problem of flickering in case the previously selected area
overlaps with the new one.
static void select_begin(GtkMathView* math_view, GdomeElement* elem, gint state) { gtk_math_view_freeze(math_view); if (root_selected != NULL) gtk_math_view_unselect(math_view, root_selected); first_selected = root_selected = elem; if (root_selected != NULL) gtk_math_view_select(math_view, elem); gtk_math_view_thaw(math_view); } |
Next we have to handle the signal emitted as the user drags the mouse keeping the button pressed. The idea is that first_selected remembers the element on which selection was initiated. As the mouse pointer is moved over the document, it crosses other elements. From first_selected and the current element elem it is possible to compute the smallest DOM subtree selected. In the sample code this operation is accomplished by the common_ancestor, which is left unspecified here.
static void select_over(GtkMathView* math_view, GdomeElement* elem, gint state) { gtk_math_view_freeze(math_view); if (root_selected != NULL) gtk_math_view_unselect(math_view, root_selected); root_selected = common_ancestor(first_selected, elem); if (root_selected != NULL) gtk_math_view_select(math_view, elem); gtk_math_view_thaw(math_view); } |
Note that the sample code does not implement any mechanism for semantic selection, but the idea is that the two signal handlers (as well as the remaining ones not shown here for simplicity), can be made as complex as the application needs. In particular, the computation of the selected root (common_ancestor) can be specialized so to search the smallest DOM subtree that meets the desired requirements as the application needs.
In order to complete the application, let us examine the main
function, which creates the graphical interface, along with an
instance of the GtkMathView widget, attaches the delete_event
to the closing button of the window so that the window is
automatically destroyed when the user closes it, and connects the
signal handlers. Then the document whose URI is passed on the command
line of the application is loaded into GtkMathView, and the control is
finally transferred to GTK+.
main(int argc, char *argv[]) { gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect(GTK_OBJECT(window), "delete_event", (GtkSignalFunc) gtk_main_quit, NULL); gtk_widget_show(window); main_vbox = gtk_vbox_new(FALSE, 1); gtk_container_border_width(GTK_CONTAINER(main_vbox), 1); gtk_container_add(GTK_CONTAINER(window), main_vbox); gtk_widget_show(main_vbox); main_area = gtk_math_view_new(NULL, NULL); gtk_widget_show(main_area); gtk_signal_connect_object (GTK_OBJECT (main_area), "click", GTK_SIGNAL_FUNC(click), (gpointer) main_area); gtk_signal_connect_object (GTK_OBJECT (main_area), "select_begin", GTK_SIGNAL_FUNC(select_begin), (gpointer) main_area); gtk_signal_connect_object (GTK_OBJECT (main_area), "select_over", GTK_SIGNAL_FUNC(select_over), (gpointer) main_area); scrolled_area = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_area), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_widget_show(scrolled_area); gtk_container_add(GTK_CONTAINER(scrolled_area), main_area); gtk_box_pack_start(GTK_BOX(main_vbox), scrolled_area, TRUE, TRUE, 0); load_document(argv[1]); gtk_main(); } |
A note on memory management. It is important to mention that
the objects of the DOM implementation (\code{Gdome2}) used in the
sample code are subject to a memory management system that is based on
reference counting. This means that every time a pointer to a DOM
object (like a GdomeElement*
in the example) is stored in some
variable, the application has to explicitly increment its reference
counter so that the object is not deallocated. For the sake of brevity
every operation involving the reference counting mechanism has been
omitted, but it is crucial to use it correctly in every application,
no matter how simple the operations are. In this respect, the use of
the corresponding C++ library (GMetaDOM
) simplifies
significantly the work of the programmer, as the DOM objects are
accessed by means of smart pointers that take care of the
reference counter automatically, without explicit intervention from
the programmer's side.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
MathMLRenderingEngine
which provides access to all the
functionalities of the rendering engine from a C++ program. The GTK+
widget is just a wrapper of this class with particular support for
GTK.
5.1 Lengths About Lengths 5.2 Boxes and Rectangles 5.3 The MathMLRenderingEngine Class
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
From the point of view of the programmer, a scaled point is a floating point number, though it can be turned into fixed-pointer number giving the option `--disable-floating' while configuring the widget. Doing so is not particularly recommended, since with most modern microprocessor floating-point arithmetics is rather efficient.
Another unit of measure which is of particular interest for the programmer is the pixel. Unfortunately, there is not a unique correspondence between pixels and scaled points. Theoretically, their relationship should depend on the resolution of the output device involved for rendering (usually, the display). Since this resolution is not available in general and often is also misconfigured, it has been fixed in the rendering engine to be 72 dots per inch (DPI), which gives pretty good results. Its value can be changed by modifing the file `src/defs.h'.
The following table summarizes the relationships between scaled points and the other units of measure recognized by the widget.
Unit | Name | scaled points | ||
mm | millimeter | 186467.98 | ||
cm | centimeter | 1864679.8 | ||
pt | point | 65536 | ||
pc | pica | 786432 | ||
in | inch | 65536 * 72.27 | ||
px | pixel | 65536 * 72.27 / DPI |
The include file `src/scaled.hh' defines several conversion functions to convert from one unit to another. The following table summarizes the conversion availables.
The system of coordinates depends on the actual drawing area used for the rendering. For example, the standard "browser-like" coordinate system has the vertical components growing to the bottom. On the other hand, PostScript has the vertical components growing to the top. In either case, when referring to vertical coordinates, "lower" means "nearer to the origin".
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.2.1 Rectangles 5.2.2 Bounding Boxes
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A rectangle is a tuple consisting of four components which locate the element by means of absolute coordinates.
true
if the rectangle (partially) overlaps with rect.
true
if the rectangle is null, that is if either width or height
is strictly less than a predefined constant EPSILON
.
true
if the point (x, y) is inside the rectangle.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A bounding box is a tuple which identifies the extent of an element, but not its absolute position.
true
if the box is null.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
NULL
then the engine will try to open the
default configuration file (usually located in
`/usr/local/share/gtkmathview').
NULL
pointer to
an already instantiated DrawingArea
object and fm must be
a non-NULL
pointer to an already instantiated
FontManager
object.
true
if the document has been
loaded correctly, false
otherwise.
true
if the document has been loaded correctly, false
otherwise.
math
element is
elem. Return true
if the document has been loaded
correctly, false
otherwise.
NULL
), then only elements whose
bounding box has a non-empty intersection with rect are set as
"dirty". If rect is NULL
, all the elements in the
document are set as "dirty". Only dirty elements will be drawn in
the next call to the update method.
NULL
, or all MathML
elements whose bounding box has a non-empty intersection with
rect.
0
if
there is no element at that coordinates.
true
, disable otherwise. The
document is updated at each invocation of this method. Anti-aliasing
is available with Type1 fonts only and it is much slower than
non-anti-aliased mode.
true
if anti-aliasing is enabled.
false
. Note also that transparency is currently supported
for Type1 fonts only.
true
if transparency is enabled.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The GTK+ interface provides a set of high-level methods for the creation, the usage, and the destruction of instances of the GtkMathView widget.
GtkMathView
class. It is not
normally needed, unless one is subclassing gtkmathview
.
GtkMathView
class. Remember that
all methods working with the widget takes a pointer to
GtkMathView
.
GtkMathView
class. This macro is
used internally, it is not normally needed.
GtkMathView
object. It is normally used as a runtime check before casting
object to the GtkMathView
type.
GtkMathView
. Used
internally.
GtkMathView
. It allocates a
new GtkMathView
object. You can pass a couple of adjustments
for the scrolling bars, or just NULL
in the case you want the
widget to allocate its own scrolling bars.
gtk_math_view_thaw
method. It can be useful to stop automatic update of the widget in
those cases in which a large number of modifications to the source
document tree are done, so that it would be inefficient and useless to
update the view at every single modification.
gtk_math_view_freeze
method. Any modification to the source
document tree that occurred while the widget was "frozen" is
displayed at this time.
TRUE
is returned, FALSE
otherwise.
TRUE
is returned, FALSE
otherwise.
math
element in the MathML
namespace.
TRUE
if elem is selected, FALSE
otherwise.
FALSE
and x and y are left
unchanged.
FALSE
and rect is left unchanged.
gtk_math_view_get_width
.
NULL
, if you are interested in only one of
the two values.
GdkPixmap
used by the
widget as the backbuffer.
GtkFrame
used by the widget to
draw the border around the drawable area.
TRUE
if anti-aliasing is enabled (even if it is not
supported), FALSE
otherwise.
0
(very few messages, in case of error only) to
3
(all messages). Useful for debugging purposes.
TRUE
if you don't
want to render colors in PostScript (this may be useful to print the
document on a black-and-white printer).
FONT_MANAGER_GTK
to use the GTK font manager (actually, this is
just a wrapper for the X font manager). This is the default.
Alternatively, use FONT_MANAGER_T1
to use t1lib
and
Type1 fonts. This font manager is availabe only if you have installed
the t1lib
library.
NULL
if the area clicked does not correspond to any MathML
element. state represents the status of the control keys at the
moment of the click event. Its possible values are the same as for the
GdkModifier
type.
click
signal.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
There are some tools provided along the widget. We will shortly describe them in the following two sections.
7.1 mathmlviewer
A simple viewer application. 7.2 mathml2ps
A MathML => PostScript conversion utility.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
mathmlviewer
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
mathml2ps
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you think that the problem may be of interest for other people too, then I encourage to subscribe and post the report on the mailing list. You can subscribe by sending an empty email to the address gtkmathview-subscribe at cs.unibo.it.
[Top] | [Contents] | [Index] | [ ? ] |
See url{http://www.w3.org/TR/MathML2
[Top] | [Contents] | [Index] | [ ? ] |
1. Overview
2. Usage
2.1 Download3. Interactivity Support
2.2 Requirements
2.3 Installing
2.4 Compile and Link
2.5 Configuration
2.5.1 Main Configuration File
2.5.2 Operator Dictionary
2.5.3 Font Setup
3.1 Selection4. Sample Application
3.2 Point-and-click Functionalities
3.3 Editing
5. C++ Interface
5.1 Lengths6. GTK+ Interface
5.2 Boxes and Rectangles
5.2.1 Rectangles5.3 The MathMLRenderingEngine Class
5.2.2 Bounding Boxes
7. Tools
7.18. Bugs and Contributionsmathmlviewer
7.2mathml2ps
[Top] | [Contents] | [Index] | [ ? ] |
1. Overview
2. Usage
3. Interactivity Support
4. Sample Application
5. C++ Interface
6. GTK+ Interface
7. Tools
8. Bugs and Contributions
[Top] | [Contents] | [Index] | [ ? ] |
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ < ] | Back | previous section in reading order | 1.2.2 |
[ > ] | Forward | next section in reading order | 1.2.4 |
[ << ] | FastBack | previous or up-and-previous section | 1.1 |
[ Up ] | Up | up section | 1.2 |
[ >> ] | FastForward | next or up-and-next section | 1.3 |
[Top] | Top | cover (top) of document | |
[Contents] | Contents | table of contents | |
[Index] | Index | concept index | |
[ ? ] | About | this page |