g2o
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
freeglut_font.cpp File Reference
#include <iostream>
#include "freeglut_minimal.h"
Include dependency graph for freeglut_font.cpp:

Go to the source code of this file.

Namespaces

namespace  freeglut_minimal
 

Macros

#define freeglut_return_if_fail(expr)    if (!(expr)) return;
 
#define freeglut_return_val_if_fail(expr, val)    if (!(expr)) return val;
 

Functions

static SFG_StrokeFontfreeglut_minimal::fghStrokeByID (FontID font)
 
void freeglut_minimal::glutStrokeString (FontID fontID, const char *string_)
 
int freeglut_minimal::glutStrokeLength (FontID fontID, const char *string_)
 
GLfloat freeglut_minimal::glutStrokeHeight (FontID fontID)
 

Macro Definition Documentation

◆ freeglut_return_if_fail

#define freeglut_return_if_fail (   expr)     if (!(expr)) return;

Definition at line 32 of file freeglut_font.cpp.

37 {
38
39/*
40 * Matches a font ID with a SFG_StrokeFont structure pointer.
41 * This was changed to match the GLUT header style.
42 */
43static SFG_StrokeFont* fghStrokeByID(FontID font) {
44 if (font == GLUT_STROKE_ROMAN) return (SFG_StrokeFont*)&fgStrokeRoman;
45 if (font == GLUT_STROKE_MONO_ROMAN)
46 return (SFG_StrokeFont*)&fgStrokeMonoRoman;
47
48 std::cerr << "stroke font " << (int)font << " not found" << std::endl;
49 return 0;
50}
51
52void glutStrokeString(FontID fontID, const char* string_) {
53 const unsigned char* string = reinterpret_cast<const unsigned char*>(string_);
54 unsigned char c;
55 int i, j;
56 float length = 0.0;
57 SFG_StrokeFont* font;
58 // FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeString" );
59 font = fghStrokeByID(fontID);
61 if (!string || !*string) return;
62
63 /*
64 * Step through the string, drawing each character.
65 * A newline will simply translate the next character's insertion
66 * point back to the start of the line and down one line.
67 */
68 while ((c = *string++))
69 if (c < font->Quantity) {
70 if (c == '\n') {
71 glTranslatef(-length, -(float)(font->Height), 0.0);
72 length = 0.0;
73 } else /* Not an EOL, draw the bitmap character */
74 {
75 const SFG_StrokeChar* schar = font->Characters[c];
76 if (schar) {
77 const SFG_StrokeStrip* strip = schar->Strips;
78
79 for (i = 0; i < schar->Number; i++, strip++) {
80 glBegin(GL_LINE_STRIP);
81 for (j = 0; j < strip->Number; j++)
82 glVertex2f(strip->Vertices[j].X, strip->Vertices[j].Y);
83
84 glEnd();
85 }
86
87 length += schar->Right;
88 glTranslatef(schar->Right, 0.0f, 0.0f);
89 }
90 }
91 }
92}
93
94/*
95 * Return the width of a string drawn using a stroke font
96 */
97int glutStrokeLength(FontID fontID, const char* string_) {
98 const unsigned char* string = reinterpret_cast<const unsigned char*>(string_);
99 unsigned char c;
100 float length = 0.0;
101 float this_line_length = 0.0;
102 SFG_StrokeFont* font;
103 // FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeLength" );
104 font = fghStrokeByID(fontID);
106 if (!string || !*string) return 0;
107
108 while ((c = *string++))
109 if (c < font->Quantity) {
110 if (c == '\n') /* EOL; reset the length of this line */
111 {
112 if (length < this_line_length) length = this_line_length;
113 this_line_length = 0.0;
114 } else /* Not an EOL, increment the length of this line */
115 {
116 const SFG_StrokeChar* schar = font->Characters[c];
117 if (schar) this_line_length += schar->Right;
118 }
119 }
120 if (length < this_line_length) length = this_line_length;
121 return (int)(length + 0.5);
122}
123
124/*
125 * Returns the height of a stroke font
126 */
127GLfloat glutStrokeHeight(FontID fontID) {
128 SFG_StrokeFont* font;
129 // FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeHeight" );
130 font = fghStrokeByID(fontID);
132 return font->Height;
133}
134
135} // namespace freeglut_minimal
136
137/*** END OF FILE ***/
#define freeglut_return_if_fail(expr)
#define freeglut_return_val_if_fail(expr, val)
struct tagSFG_StrokeChar SFG_StrokeChar
const SFG_StrokeFont fgStrokeMonoRoman
static SFG_StrokeFont * fghStrokeByID(FontID font)
void glutStrokeString(FontID fontID, const char *string_)
const SFG_StrokeFont fgStrokeRoman
struct tagSFG_StrokeFont SFG_StrokeFont
struct tagSFG_StrokeStrip SFG_StrokeStrip
int glutStrokeLength(FontID fontID, const char *string_)
GLfloat glutStrokeHeight(FontID fontID)

◆ freeglut_return_val_if_fail

#define freeglut_return_val_if_fail (   expr,
  val 
)     if (!(expr)) return val;

Definition at line 34 of file freeglut_font.cpp.