Font(3X) manual page
Table of Contents
Font - used for text output with Painter
#include <ivplus/fonth>
Font defines how characters will be represented on the screen.
The predefined variable stdfont is a small fixed width font that Painter
operations use by default. Font is derived from Resource and has an initial
reference count of zero.
Font -> Resource
Creates a new font from the unique string String.
Creates a new font from name.
Creates
a new font from the specified font implementation. This is a protected constructor.
Returns the baseline of the font in
pixels.
Returns true if the font contains only
fixed width characters.
Returns the height of the font
in pixels.
Finds
the target character in a string that contains the pixel which would be
offset pixels from the left, if the string were displayed. A negative offset
will return an index of zero and an offset greater than the length of the
string will return an index equal to the length of the string. If between
is true and the offset is beyond the center of the target, the index of
the character following the target is returned. Otherwise, the index of
target is returned.
Finds the target character in a string that contains
the pixel which would be offset pixels from the left, if the string were
displayed. A negative offset will return an index of zero and an offset
greater than len or the length of the string, will return an index equal
to the length of the string. If between is true and the offset is beyond
the center of the target, the index of the character following the target
is returned. Otherwise, the index of the target is returned.
Returns a pointer to a font after performing
a lookup of the unique string font.
Returns a pointer to a font after performing a lookup of the string
font.
Returns the name of the current font.
Returns a pointer to the FontRep for the font.
The FontRep class is a low level interface to X Windows. It is not expected
that developers will need details of the FontRep X interface so the FontRep
class is not documented.
Returns the
width in pixels that string would have if it were displayed in this font.
Returns the width in pixels
that a subset of string len characters long would have if it were displayed
in this font.
None.
None.
// Font Example
#include <ivplus/box.h>
#include <ivplus/font.h>
#include <ivplus/frame.h>
#include <ivplus/message.h>
#include <ivplus/painter.h>
#include <ivplus/string.h>
#include <ivplus/world.h>
// Derive a class from message so that the font string passed
// can be displayed as a message using that font.
class DispFont : public Message {
public:
DispFont(const char* ftext, float scale =1.0);
DispFont(const IVString& ftext, float scale =1.0);
~DispFont();
private:
void Reconfig();
Font* font;
};
DispFont::DispFont(const char* ftext, float scale)
: Message(ftext)
{
font = new Font(ftext, scale);
font->Reference(); // increment the reference count
};
DispFont::DispFont(const IVString& ftext, float scale)
: Message(ftext.string())
{
font = new Font(ftext, scale);
font->Reference();
};
DispFont::~DispFont()
{
// Decrement the reference count, delete, if 0.
Unref(font);
};
void DispFont::Reconfig()
{
// Modify the interactor painter to use the new font.
Painter* newoutput = new Painter(output);
Unref(output); // get rid of the old one
// Use the painter just created.
output = newoutput;
// Set the font to the one created above.
output->SetFont(font);
// Call base class Reconfig.
Message::Reconfig();
};
// Set up a mechanism for the user to allow fonts with
// "-F" option on the command line.
static OptionDesc options[] = {
{"-F", "MyApp*F", OptionValueNext},
{nil}
};
int main(int argc, char **argv)
{
// Create the world to get the connection with the display.
World* world = new World("MyApp", argc, argv, options);
VBox* mainbox = new VBox();
if (world->GetAttribute("F") != nil) {
// Display the font given on the command line with "-F" option.
DispFont* msg = new DispFont(world->GetAttribute("F"));
mainbox->Insert(msg);
}
else {
// If no font specified on command line, display a few sample fonts.
// Arrange them vertically in a VBox.
// Create a font with default scale of 1.0.
DispFont* dspf1 = new DispFont("user8x16");
mainbox->Insert(dspf1);
IVString s1("8x16romankana");
// Create a font using IVString s1.
DispFont* dspf2 = new DispFont(s1);
mainbox->Insert(dspf2);
}
// Map the window.
world->InsertApplication(new Frame(mainbox, 1, BevelOut));
// Enter the event loop.
world->Run();
return 0;
}
font.h
Painter(3X)
, Resource(3X)
.
Table of Contents