Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
glcompfont.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <cgraph/alloc.h>
12#include <glcomp/glcompfont.h>
13#include <glcomp/glcompset.h>
14#include <glcomp/glpangofont.h>
16#include <glcomp/glutils.h>
17#include <GL/glut.h>
18#include <stdbool.h>
19#include <stddef.h>
20
21static void print_bitmap_string(void *font, char *s)
22{
23 if (s && strlen(s)) {
24 while (*s) {
25 glutBitmapCharacter(font, *s);
26 s++;
27 }
28 }
29}
30
31void glprintfglut(void *font, float xpos, float ypos, float zpos, char *bf) {
32 glRasterPos3f(xpos, ypos, zpos + 0.001f);
34
35
36}
37
39{
40 free(f->fontdesc);
41 if (f->tex)
43 free(f);
44
45}
46
47glCompFont *glNewFont(glCompSet *s, char *text, glCompColor *c, char *fontdesc,
48 int fs, bool is2D) {
50 font->reference = 0;
51 font->color.R = c->R;
52 font->color.G = c->G;
53 font->color.B = c->B;
54 font->color.A = c->A;
55 font->justify.VJustify = GL_FONTVJUSTIFY;
56 font->justify.HJustify = GL_FONTHJUSTIFY;
57 font->is2D=is2D;
58
59 font->glutfont = NULL;
60
61 font->fontdesc = gv_strdup(fontdesc);
62 font->size = fs;
63 font->transparent = 1;
64 font->optimize = GL_FONTOPTIMIZE;
65 if (text)
66 font->tex =
67 glCompSetAddNewTexLabel(s, font->fontdesc, font->size, text,
68 is2D);
69 return font;
70
71}
72
73
74
76{
79 parent = o->common.parent;
80 if (parent) {
81 parent = o->common.parent;
82 font->reference = 1;
83 font->color.R = parent->font->color.R;
84 font->color.G = parent->font->color.G;
85 font->color.B = parent->font->color.B;
86 font->color.A = parent->font->color.A;
87
88 font->glutfont = parent->font->glutfont;
89 font->fontdesc = gv_strdup(parent->font->fontdesc);
90 font->size = parent->font->size;
91 font->transparent = parent->font->transparent;
92 font->justify.VJustify = parent->font->justify.VJustify;
93 font->justify.HJustify = parent->font->justify.HJustify;
94 font->optimize = parent->font->optimize;
95 font->is2D=parent->font->is2D;
96 if (text) {
97 if (strlen(text))
98 font->tex =
100 font->fontdesc, font->size,
101 text, parent->font->is2D);
102 }
103 } else { /*no parent */
104
105 glCompColor c;
110 font = glNewFont(o->common.compset, text, &c,
112 }
113 return font;
114}
115
116/*texture base 3d text rendering*/
117void glCompDrawText3D(glCompFont *f, float x, float y, double z, float w,
118 float h) {
119 glEnable(GL_BLEND); // Turn Blending On
120 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
121 glEnable(GL_TEXTURE_2D);
122 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
123 glBindTexture(GL_TEXTURE_2D,f->tex->id);
124 glBegin(GL_QUADS);
125 glTexCoord2d(0.0f, 1.0f);glVertex3d(x,y,z);
126 glTexCoord2d(1.0f, 1.0f);glVertex3d(x+w,y,z);
127 glTexCoord2d(1.0f, 0.0f);glVertex3d(x+w,y+h,z);
128 glTexCoord2d(0.0f, 0.0f);glVertex3d(x,y+h,z);
129 glEnd();
130
131 glDisable(GL_TEXTURE_2D);
132 glEnable(GL_BLEND);
133
134}
135
136void glCompDrawText(glCompFont *f, float x, float y) {
137 glRasterPos2f(x, y);
138 glDrawPixels(f->tex->width, f->tex->height, GL_RGBA, GL_UNSIGNED_BYTE, f->tex->data);
139}
140
141/*text rendering functions, depends on a globject to retrieve stats*/
143{
144 if (!f->tex)
145 return;
146 float x = 0;
147 float y = 0;
148 glCompCommon ref = parentObj->common;
149 switch (f->justify.HJustify)
150 {
153 x = ref.refPos.x;
154 break;
156 x = ref.refPos.x + (ref.width - f->tex->width);
157 break;
159 x = ref.refPos.x + (ref.width - f->tex->width) / 2.0f;
160 break;
161 }
162 switch (f->justify.VJustify) {
165 y = ref.pos.y;
166 break;
168 x = ref.refPos.y + (ref.height - f->tex->height);
169 break;
171 y = ref.refPos.y + (ref.height - f->tex->height) / 2.0f;
172 break;
173 }
174
176 glCompDrawText(f,x,y);
177
178}
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
Definition alloc.h:101
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define parent(i)
Definition closest.c:78
#define GLCOMPSET_FONT_COLOR_ALPHA
Definition glcompdefs.h:65
#define GLCOMPSET_FONT_COLOR_B
Definition glcompdefs.h:64
#define GL_FONTOPTIMIZE
Definition glcompdefs.h:67
@ glFontVJustifyTop
Definition glcompdefs.h:83
@ glFontVJustifyBottom
Definition glcompdefs.h:84
@ glFontVJustifyCenter
Definition glcompdefs.h:84
@ glFontVJustifyNone
Definition glcompdefs.h:83
@ glFontHJustifyLeft
Definition glcompdefs.h:85
@ glFontHJustifyRight
Definition glcompdefs.h:86
@ glFontHJustifyCenter
Definition glcompdefs.h:86
@ glFontHJustifyNone
Definition glcompdefs.h:85
#define GL_FONTVJUSTIFY
Definition glcompdefs.h:70
#define GLCOMPSET_FONT_COLOR_R
Definition glcompdefs.h:62
#define GLCOMPSET_FONT_SIZE
Definition glcompdefs.h:48
#define GL_FONTHJUSTIFY
Definition glcompdefs.h:71
#define GLCOMPSET_FONT_DESC
Definition glcompdefs.h:66
#define GLCOMPSET_FONT_COLOR_G
Definition glcompdefs.h:63
glCompFont * glNewFont(glCompSet *s, char *text, glCompColor *c, char *fontdesc, int fs, bool is2D)
Definition glcompfont.c:47
static void print_bitmap_string(void *font, char *s)
Definition glcompfont.c:21
void glCompRenderText(glCompFont *f, glCompObj *parentObj)
Definition glcompfont.c:142
glCompFont * glNewFontFromParent(glCompObj *o, char *text)
Definition glcompfont.c:75
void glDeleteFont(glCompFont *f)
Definition glcompfont.c:38
void glCompDrawText(glCompFont *f, float x, float y)
Definition glcompfont.c:136
void glprintfglut(void *font, float xpos, float ypos, float zpos, char *bf)
Definition glcompfont.c:31
void glCompDrawText3D(glCompFont *f, float x, float y, double z, float w, float h)
Definition glcompfont.c:117
glCompTex * glCompSetAddNewTexLabel(glCompSet *s, char *def, int fs, char *text, bool is2D)
void glCompDeleteTexture(glCompTex *t)
void glCompSetColor(glCompColor *c)
Definition glutils.c:294
void free(void *)
node NULL
Definition grammar.y:149
static int z
$2 font
Definition htmlparse.y:498
void ref(Site *v)
Definition site.c:59
glCompCommon common
Definition glcompdefs.h:274
void * parent
Definition glcompdefs.h:216
glCompPoint refPos
Definition glcompdefs.h:209
void * compset
Definition glcompdefs.h:215
glCompColor color
Definition glcompdefs.h:178
glCompTex * tex
Definition glcompdefs.h:181
char * fontdesc
Definition glcompdefs.h:177
glCompJustify justify
Definition glcompdefs.h:184
glCompHJustify HJustify
Definition glcompdefs.h:136
glCompVJustify VJustify
Definition glcompdefs.h:135
uint32_t id
Definition glcompdefs.h:162
unsigned char * data
Definition glcompdefs.h:170
float height
Definition glcompdefs.h:166
float width
Definition glcompdefs.h:165
Definition grammar.c:93