Graphviz 13.0.0~dev.20241220.2304
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 <glcomp/glcompfont.h>
12#include <glcomp/glcompset.h>
13#include <glcomp/glpangofont.h>
15#include <glcomp/glutils.h>
16#include <GL/glut.h>
17#include <stdbool.h>
18#include <stddef.h>
19#include <util/alloc.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 *f = (glCompFont){0};
44}
45
46glCompFont glNewFont(glCompSet *s, char *text, glCompColor *c, char *fontdesc,
47 int fs, bool is2D) {
48 glCompFont font = {0};
49 font.color.R = c->R;
50 font.color.G = c->G;
51 font.color.B = c->B;
52 font.color.A = c->A;
53 font.justify.VJustify = glFontVJustifyNone;
54 font.justify.HJustify = glFontHJustifyNone;
55 font.is2D = is2D;
56
57 font.glutfont = NULL;
58
59 font.fontdesc = gv_strdup(fontdesc);
60 font.size = fs;
61 font.transparent = 1;
62 if (text)
63 font.tex =
64 glCompSetAddNewTexLabel(s, font.fontdesc, font.size, text,
65 is2D);
66 return font;
67
68}
69
72 glCompFont font = {0};
73 parent = o->common.parent;
74 if (parent) {
75 parent = o->common.parent;
76 font.color.R = parent->font.color.R;
77 font.color.G = parent->font.color.G;
78 font.color.B = parent->font.color.B;
79 font.color.A = parent->font.color.A;
80
81 font.glutfont = parent->font.glutfont;
82 font.fontdesc = gv_strdup(parent->font.fontdesc);
83 font.size = parent->font.size;
84 font.transparent = parent->font.transparent;
85 font.justify.VJustify = parent->font.justify.VJustify;
86 font.justify.HJustify = parent->font.justify.HJustify;
87 font.is2D = parent->font.is2D;
88 if (text) {
89 if (strlen(text))
90 font.tex =
92 font.fontdesc, font.size,
93 text, parent->font.is2D);
94 }
95 } else { /*no parent */
96
102 font = glNewFont(o->common.compset, text, &c,
104 }
105 return font;
106}
107
108/*texture base 3d text rendering*/
109void glCompDrawText3D(glCompFont f, float x, float y, double z, float w,
110 float h) {
111 glEnable(GL_BLEND); // Turn Blending On
112 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
113 glEnable(GL_TEXTURE_2D);
114 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
115 glBindTexture(GL_TEXTURE_2D, f.tex->id);
116 glBegin(GL_QUADS);
117 glTexCoord2d(0.0f, 1.0f);glVertex3d(x,y,z);
118 glTexCoord2d(1.0f, 1.0f);glVertex3d(x+w,y,z);
119 glTexCoord2d(1.0f, 0.0f);glVertex3d(x+w,y+h,z);
120 glTexCoord2d(0.0f, 0.0f);glVertex3d(x,y+h,z);
121 glEnd();
122
123 glDisable(GL_TEXTURE_2D);
124 glEnable(GL_BLEND);
125
126}
127
128void glCompDrawText(glCompFont f, float x, float y) {
129 glRasterPos2f(x, y);
130 glDrawPixels(f.tex->width, f.tex->height, GL_RGBA, GL_UNSIGNED_BYTE, f.tex->data);
131}
132
133/*text rendering functions, depends on a globject to retrieve stats*/
135 if (!f.tex)
136 return;
137 float x = 0;
138 float y = 0;
139 glCompCommon ref = parentObj->common;
140 switch (f.justify.HJustify) {
142 x = ref.refPos.x;
143 break;
145 x = ref.refPos.x + (ref.width - (float)f.tex->width) / 2.0f;
146 break;
147 }
148 switch (f.justify.VJustify) {
150 y = ref.pos.y;
151 break;
153 y = ref.refPos.y + (ref.height - (float)f.tex->height) / 2.0f;
154 break;
155 }
156
158 glCompDrawText(f, x, y);
159}
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
Definition alloc.h:101
#define parent(i)
Definition closest.c:80
#define GLCOMPSET_FONT_COLOR_ALPHA
Definition glcompdefs.h:50
#define GLCOMPSET_FONT_COLOR_B
Definition glcompdefs.h:49
@ glFontVJustifyCenter
Definition glcompdefs.h:63
@ glFontVJustifyNone
Definition glcompdefs.h:63
@ glFontHJustifyCenter
Definition glcompdefs.h:64
@ glFontHJustifyNone
Definition glcompdefs.h:64
#define GLCOMPSET_FONT_COLOR_R
Definition glcompdefs.h:47
#define GLCOMPSET_FONT_SIZE
Definition glcompdefs.h:45
#define GLCOMPSET_FONT_DESC
Definition glcompdefs.h:51
#define GLCOMPSET_FONT_COLOR_G
Definition glcompdefs.h:48
glCompFont glNewFont(glCompSet *s, char *text, glCompColor *c, char *fontdesc, int fs, bool is2D)
Definition glcompfont.c:46
static void print_bitmap_string(void *font, char *s)
Definition glcompfont.c:21
void glCompDrawText3D(glCompFont f, float x, float y, double z, float w, float h)
Definition glcompfont.c:109
glCompFont glNewFontFromParent(glCompObj *o, char *text)
Definition glcompfont.c:70
void glDeleteFont(glCompFont *f)
Definition glcompfont.c:38
void glCompDrawText(glCompFont f, float x, float y)
Definition glcompfont.c:128
void glCompRenderText(glCompFont f, glCompObj *parentObj)
Definition glcompfont.c:134
void glprintfglut(void *font, float xpos, float ypos, float zpos, char *bf)
Definition glcompfont.c:31
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:163
static int z
$2 font
Definition htmlparse.y:300
void ref(Site *v)
Definition site.c:59
void * parent
Definition glcompdefs.h:187
glCompPoint refPos
Definition glcompdefs.h:180
glCompSet * compset
compset
Definition glcompdefs.h:186
glCompColor color
Definition glcompdefs.h:150
glCompTex * tex
Definition glcompdefs.h:153
char * fontdesc
Definition glcompdefs.h:149
glCompJustify justify
Definition glcompdefs.h:155
glCompHJustify HJustify
Definition glcompdefs.h:111
glCompVJustify VJustify
Definition glcompdefs.h:110
object prototype
Definition glcompdefs.h:199
glCompCommon common
Definition glcompdefs.h:200
uint32_t id
Definition glcompdefs.h:134
unsigned char * data
Definition glcompdefs.h:142
Definition grammar.c:93