libgeda

o_text_basic.c File Reference

functions for the text and fonts More...

#include <config.h>
#include <missing.h>
#include <stdio.h>
#include <math.h>
#include <sys/stat.h>
#include "libgeda_priv.h"
Include dependency graph for o_text_basic.c:

Go to the source code of this file.

Defines

#define GEDA_FONT_FACTOR   1.3
 Scale factor between legacy gschem font units and postscript points.
#define PRINT_LINE_SPACING   1.12
 Scale factor font height and line-spacing (for print only)

Functions

static void update_disp_string (OBJECT *object)
 update the visible part of a string
int world_get_text_bounds (TOPLEVEL *toplevel, OBJECT *o_current, int *left, int *top, int *right, int *bottom)
 calculate and return the boundaries of a text object
gboolean o_text_get_position (TOPLEVEL *toplevel, gint *x, gint *y, OBJECT *object)
 get the position of a text object
int o_text_num_lines (const char *string)
 count the lines of a text string
OBJECTo_text_new (TOPLEVEL *toplevel, char type, int color, int x, int y, int alignment, int angle, const char *string, int size, int visibility, int show_name_value)
 Creates a text OBJECT and the graphical objects representing it.
void o_text_recalc (TOPLEVEL *toplevel, OBJECT *o_current)
 update the visual boundaries of the text object
OBJECTo_text_read (TOPLEVEL *toplevel, const char *first_line, TextBuffer *tb, unsigned int release_ver, unsigned int fileformat_ver, GError **err)
 read a text object from a char buffer
char * o_text_save (TOPLEVEL *toplevel, OBJECT *object)
 Create a string representation of the text object.
void o_text_recreate (TOPLEVEL *toplevel, OBJECT *o_current)
 recreate the graphics of a text object
void o_text_translate_world (TOPLEVEL *toplevel, int dx, int dy, OBJECT *o_current)
 move a text object
OBJECTo_text_copy (TOPLEVEL *toplevel, OBJECT *o_current)
 create a copy of a text object
void o_text_print_text_string (FILE *fp, char *string, int unicode_count, gunichar *unicode_table)
 write a text string to a postscript file
void o_text_print (TOPLEVEL *toplevel, FILE *fp, OBJECT *o_current, int origin_x, int origin_y, int unicode_count, gunichar *unicode_table)
 print a text object into a postscript file
void o_text_rotate_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, int angle, OBJECT *object)
 rotate a text object around a centerpoint
void o_text_mirror_world (TOPLEVEL *toplevel, int world_centerx, int world_centery, OBJECT *object)
 mirror a text object horizontaly at a centerpoint
double o_text_shortest_distance (OBJECT *object, int x, int y, int force_solid)
 Calculates the distance between the given point and the closest point on the text.
void o_text_set_string (TOPLEVEL *toplevel, OBJECT *obj, const gchar *new_string)
 Set the string displayed by a text object.
const gchar * o_text_get_string (TOPLEVEL *toplevel, OBJECT *obj)
 Get the string displayed by a text object.
void o_text_set_rendered_bounds_func (TOPLEVEL *toplevel, RenderedBoundsFunc func, void *user_data)
 Set the font-renderer-specific bounds function.
double o_text_get_font_size_in_points (TOPLEVEL *toplevel, OBJECT *object)
 Return font size of a text object in postscript points.

Variables

int tab_in_chars = 8

Detailed Description

The font definitions

Each letter of the font is defined in a single font symbol file. In the font symbol file, the character width is defined in the second line. The first line contains the file format version.

All remaining lines are basic graphical lines. They build the appearance of the character.

o_text_font_overview.png

The height of capital characters in the font files is 26. The size of small letters is 16. The space below the zero line is used by characters like g, p or q. The space above 26 is used by diacritic marks like accents, breve, circumflex mostly in european characters.

The text definitions

The text is stored and printed in several different representations.

In the gEDA files the text is just a string. It is stored unmodified in OBJECT->text->string.

If the string is an attribute with an equal sign as delimiter between an attribute name and an attribute value, then it is possible to hide some parts of the text. The still visible part of an attribute is stored in OBJECT->text->disp_string.

o_text_text_overview.png

To draw the text in gschem, the string is interpreted and converted to a list of basic graphical objects. The basic line objects are collected from the font character objects.

Definition in file o_text_basic.c.


Define Documentation

#define GEDA_FONT_FACTOR   1.3
Description
gschem fonts are nominally specified in points, however there is a difference in how the specified font size corresponds to the metrics of the font when compared to typical typographic usage.

The following factor was impirically determined to approximately match the cap-height between the legacy gschem font, and fonts rendered using pango.

Definition at line 91 of file o_text_basic.c.

#define PRINT_LINE_SPACING   1.12
Description
Specifies the scale factor between the nominal font size and the inter- line spacing used to render it when printing.

Definition at line 99 of file o_text_basic.c.


Function Documentation

static void update_disp_string ( OBJECT object) [static]
Function Description
If a string is an attribute, then it is possible to hide the name or the value part of the attribute string. This functions updates the text->disp_string according to the object->show_name_value settings
Parameters:
[in]objectThe OBJECT to update

Definition at line 113 of file o_text_basic.c.

Here is the call graph for this function:

int world_get_text_bounds ( TOPLEVEL toplevel,
OBJECT o_current,
int *  left,
int *  top,
int *  right,
int *  bottom 
)
Function Description
This function calculates the object boudaries of a text object.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]o_currenta text object
[out]leftthe left world coord
[out]topthe top world coord
[out]rightthe right world coord
[out]bottomthe bottom world coord

Definition at line 166 of file o_text_basic.c.

gboolean o_text_get_position ( TOPLEVEL toplevel,
gint *  x,
gint *  y,
OBJECT object 
)
Function Description
This function gets the position of the base point of a text object.
Parameters:
[in]toplevelThe toplevel environment.
[out]xpointer to the x-position
[out]ypointer to the y-position
[in]objectThe object to get the position.
Returns:
TRUE if successfully determined the position, FALSE otherwise

Definition at line 189 of file o_text_basic.c.

int o_text_num_lines ( const char *  string)
Function Description
This function just counts the number of lines that are in the string.
Parameters:
[in]stringtext string to count the lines
Returns:
the number of lines

Definition at line 206 of file o_text_basic.c.

OBJECT* o_text_new ( TOPLEVEL toplevel,
char  type,
int  color,
int  x,
int  y,
int  alignment,
int  angle,
const char *  string,
int  size,
int  visibility,
int  show_name_value 
)
Function Description
Create an OBJECT of type OBJ_TEXT.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]typeOBJ_TEXT (TODO: why bother)
[in]colorThe color of the text.
[in]xWorld x coord of text.
[in]yWorld y coord of text.
[in]alignmentHow text bounding box aligns on (x, y).
[in]angleAngle at which text will appear.
[in]stringThe text (TODO: can be char const *)!
[in]sizeText size.
[in]visibilityVISIBLE or INVISIBLE.
[in]show_name_valueSHOW_NAME_VALUE or friends.
Returns:
Pointer to text OBJECT.
Note:
Caller is responsible for string; this function allocates its own copy.

Definition at line 251 of file o_text_basic.c.

Here is the call graph for this function:

void o_text_recalc ( TOPLEVEL toplevel,
OBJECT o_current 
)
Function Description
This function updates the boundaries of the object o_current.
Parameters:
[in]toplevelThe TOPLEVEL object
[in]o_currentThe OBJECT to update

Definition at line 297 of file o_text_basic.c.

Here is the call graph for this function:

OBJECT* o_text_read ( TOPLEVEL toplevel,
const char *  first_line,
TextBuffer tb,
unsigned int  release_ver,
unsigned int  fileformat_ver,
GError **  err 
)
Function Description
This function reads a text object from the textbuffer tb and the text starting with the line firstline. If the line object was read successfully, a new object is create and appended to the object_list.
Parameters:
[in]toplevelThe TOPLEVEL object
[in]first_linethe first line of the text
[in]tba text buffer (usually a line of a schematic file)
[in]release_verThe release number gEDA
[in]fileformat_vera integer value of the file format
Returns:
The object list, or NULL on error.

Definition at line 330 of file o_text_basic.c.

Here is the call graph for this function:

char* o_text_save ( TOPLEVEL toplevel,
OBJECT object 
)
Function Description
This function takes a text object and return a string according to the file format definition.
Parameters:
[in]toplevela TOPLEVEL structure
[in]objecta text OBJECT
Returns:
the string representation of the text OBJECT

Definition at line 485 of file o_text_basic.c.

Here is the call graph for this function:

void o_text_recreate ( TOPLEVEL toplevel,
OBJECT o_current 
)
Function Description
This function updates the underlying primary of the text object o_current.
Parameters:
toplevelThe TOPLEVEL object
o_currentThe text object to update

Definition at line 519 of file o_text_basic.c.

Here is the call graph for this function:

void o_text_translate_world ( TOPLEVEL toplevel,
int  dx,
int  dy,
OBJECT o_current 
)
Function Description
This function changes the position of a text object o_current.
Parameters:
[in]toplevelThe TOPLEVEL object
[in]dxThe x-distance to move the object
[in]dyThe y-distance to move the object
[in]o_currentThe text OBJECT to be moved

Definition at line 536 of file o_text_basic.c.

OBJECT* o_text_copy ( TOPLEVEL toplevel,
OBJECT o_current 
)
Function Description
This function creates a copy of the text object o_current.
Parameters:
[in]toplevelThe TOPLEVEL object
[in]o_currentThe object that is copied
Returns:
a new text object

Definition at line 554 of file o_text_basic.c.

Here is the call graph for this function:

void o_text_print_text_string ( FILE *  fp,
char *  string,
int  unicode_count,
gunichar *  unicode_table 
)
Function Description
This function writes the single string into the postscript file fp.
Parameters:
[in]fppointer to a FILE structure
[in]stringThe string to print
[in]unicode_countNumber of items in the unicode table
[in]unicode_tableTable of unicode items
Todo:
investigate whether the TAB character is handled correctly

Definition at line 582 of file o_text_basic.c.

void o_text_print ( TOPLEVEL toplevel,
FILE *  fp,
OBJECT o_current,
int  origin_x,
int  origin_y,
int  unicode_count,
gunichar *  unicode_table 
)
Function Description
This function writes the postscript representation of the text object o_current into the the file fp.
Parameters:
[in]toplevelThe TOPLEVEL object
[in]fppointer to a FILE structure
[in]o_currentThe OBJECT to print
[in]origin_xx-coord of the postscript origin
[in]origin_yy-coord of the postscript origin
[in]unicode_countNumber of items in the unicode table
[in]unicode_tableTable of unicode items

Definition at line 643 of file o_text_basic.c.

Here is the call graph for this function:

void o_text_rotate_world ( TOPLEVEL toplevel,
int  world_centerx,
int  world_centery,
int  angle,
OBJECT object 
)
Function Description
This function rotates a text object around the point (world_centerx, world_centery).
Parameters:
[in]toplevelThe TOPLEVEL object
[in]world_centerxx-coord of the rotation center
[in]world_centeryy-coord of the rotation center
[in]angleThe angle to rotate the text object
[in]objectThe text object
Note:
only steps of 90 degrees are allowed for the angle

Definition at line 808 of file o_text_basic.c.

Here is the call graph for this function:

void o_text_mirror_world ( TOPLEVEL toplevel,
int  world_centerx,
int  world_centery,
OBJECT object 
)
Function Description
This function mirrors a text object horizontaly at the point (world_centerx, world_centery).
Parameters:
[in]toplevelThe TOPLEVEL object
[in]world_centerxx-coord of the mirror position
[in]world_centeryy-coord of the mirror position
[in]objectThe text object

Definition at line 844 of file o_text_basic.c.

Here is the call graph for this function:

double o_text_shortest_distance ( OBJECT object,
int  x,
int  y,
int  force_solid 
)

This function will calculate the distance to the text regardless if the text is visible or not.

Parameters:
[in]objectThe text OBJECT.
[in]xThe x coordinate of the given point.
[in]yThe y coordinate of the given point.
[in]force_solidIf true, force treating the object as solid.
Returns:
The shortest distance from the object to the point. If the distance cannot be calculated, this function returns a really large number (G_MAXDOUBLE). With an invalid parameter, this funciton returns G_MAXDOUBLE.

Definition at line 938 of file o_text_basic.c.

void o_text_set_string ( TOPLEVEL toplevel,
OBJECT obj,
const gchar *  new_string 
)
Function Description
Updates the text object with a new text string.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objThe text object.
[in]new_stringThe new value.

Definition at line 961 of file o_text_basic.c.

Here is the call graph for this function:

const gchar* o_text_get_string ( TOPLEVEL toplevel,
OBJECT obj 
)
Function Description
Retrieve the text string from a text object. The returned string should be treated as constant.
Parameters:
[in]toplevelThe TOPLEVEL object.
[in]objThe text object.
Returns:
The text object's string, or NULL on failure.

Definition at line 990 of file o_text_basic.c.

void o_text_set_rendered_bounds_func ( TOPLEVEL toplevel,
RenderedBoundsFunc  func,
void *  user_data 
)
Function Description
Set the function to be used to calculate text bounds for a given TOPLEVEL.
Parameters:
[in]toplevelThe TOPLEVEL object
[in]funcFunction to use.
[in]user_dataUser data to be passed to the function.

Definition at line 1009 of file o_text_basic.c.

double o_text_get_font_size_in_points ( TOPLEVEL toplevel,
OBJECT object 
)
Description
gEDA fonts are specified in a non-standard unit. This function applies an appopriate scaling to return the font size in postscript points.
Parameters:
[in]toplevelThe TOPLEVEL object
[in]objectThe text OBJECT whos font size to return
Returns:
The font size converted to postscript points.

Definition at line 1028 of file o_text_basic.c.


Variable Documentation

int tab_in_chars = 8

Size of a tab in characters

Definition at line 102 of file o_text_basic.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines