[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    Font(3X) manual page Table of Contents

Name

Font - used for text output with Painter

Syntax

#include <ivplus/fonth>

Description

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.

Class Hierarchy

Font -> Resource

Constructors

Font(const String&, float scale = 1.0)

Creates a new font from the unique string String.

Font(const char* name, float scale = 1.0)

Creates a new font from name.

Font(FontImpl*)

Creates a new font from the specified font implementation. This is a protected constructor.

Public Operations

int Baseline() const

Returns the baseline of the font in pixels.

boolean FixedWidth() const

Returns true if the font contains only fixed width characters.

int Height() const

Returns the height of the font in pixels.

virtual int Index(const char*, int offset, boolean between) const

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.

virtual int Index(const char*, int len, int offset, boolean between) const

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.

static const Font* lookup(const String& font)

Returns a pointer to a font after performing a lookup of the unique string font.

static const Font* lookup(const char* font)

Returns a pointer to a font after performing a lookup of the string font.

virtual const char* name() const

Returns the name of the current font.

FontRep* rep(Display*) const

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.

int Width(const char* string) const

Returns the width in pixels that string would have if it were displayed in this font.

int Width(const char* string, int len) const

Returns the width in pixels that a subset of string len characters long would have if it were displayed in this font.

Protected Operations

None.

X Resources

None.

Examples


//                          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;
}

Files

font.h

See Also

Painter(3X) , Resource(3X) .


Table of Contents