Graphviz 14.1.2~dev.20260118.1035
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 "config.h"
12
13#include <glcomp/glcompfont.h>
14#include <glcomp/glcompset.h>
15#include <glcomp/glpangofont.h>
17#include <glcomp/glutils.h>
18#include <GL/glut.h>
19#include <stdbool.h>
20#include <stddef.h>
21#include <util/alloc.h>
22
23static void print_bitmap_string(void *font, char *s)
24{
25 if (s && strlen(s)) {
26 while (*s) {
27 glutBitmapCharacter(font, *s);
28 s++;
29 }
30 }
31}
32
33void glprintfglut(void *font, float xpos, float ypos, float zpos, char *bf) {
34 glRasterPos3f(xpos, ypos, zpos + 0.001f);
36
37
38}
39
41{
42 free(f->fontdesc);
43 if (f->tex)
45 *f = (glCompFont){0};
46}
47
49 char *fontdesc, int fs, bool is2D) {
50 glCompFont font = {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 = glFontVJustifyNone;
56 font.justify.HJustify = glFontHJustifyNone;
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 if (text)
65 font.tex =
66 glCompSetAddNewTexLabel(s, font.fontdesc, font.size, text,
67 is2D);
68 return font;
69
70}
71
74 glCompFont font = {0};
75 parent = o->common.parent;
76 if (parent) {
77 parent = o->common.parent;
78 font.color.R = parent->font.color.R;
79 font.color.G = parent->font.color.G;
80 font.color.B = parent->font.color.B;
81 font.color.A = parent->font.color.A;
82
83 font.glutfont = parent->font.glutfont;
84 font.fontdesc = gv_strdup(parent->font.fontdesc);
85 font.size = parent->font.size;
86 font.transparent = parent->font.transparent;
87 font.justify.VJustify = parent->font.justify.VJustify;
88 font.justify.HJustify = parent->font.justify.HJustify;
89 font.is2D = parent->font.is2D;
90 if (text) {
91 if (strlen(text))
92 font.tex =
94 font.fontdesc, font.size,
95 text, parent->font.is2D);
96 }
97 } else { /*no parent */
98
104 font = glNewFont(o->common.compset, text, &c,
106 }
107 return font;
108}
109
110/*texture base 3d text rendering*/
111void glCompDrawText3D(glCompFont f, float x, float y, double z, float w,
112 float h) {
113 glEnable(GL_BLEND); // Turn Blending On
114 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
115 glEnable(GL_TEXTURE_2D);
116 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
117 glBindTexture(GL_TEXTURE_2D, f.tex->id);
118 glBegin(GL_QUADS);
119 glTexCoord2d(0.0f, 1.0f);glVertex3d(x,y,z);
120 glTexCoord2d(1.0f, 1.0f);glVertex3d(x+w,y,z);
121 glTexCoord2d(1.0f, 0.0f);glVertex3d(x+w,y+h,z);
122 glTexCoord2d(0.0f, 0.0f);glVertex3d(x,y+h,z);
123 glEnd();
124
125 glDisable(GL_TEXTURE_2D);
126 glEnable(GL_BLEND);
127
128}
129
130void glCompDrawText(glCompFont f, double x, double y) {
131 glRasterPos2d(x, y);
132 glDrawPixels(f.tex->width, f.tex->height, GL_RGBA, GL_UNSIGNED_BYTE, f.tex->data);
133}
134
135/*text rendering functions, depends on a globject to retrieve stats*/
137 if (!f.tex)
138 return;
139 float x = 0;
140 float y = 0;
141 glCompCommon ref = parentObj->common;
142 switch (f.justify.HJustify) {
144 x = ref.refPos.x;
145 break;
147 x = ref.refPos.x + (ref.width - (float)f.tex->width) / 2.0f;
148 break;
149 }
150 switch (f.justify.VJustify) {
152 y = ref.pos.y;
153 break;
155 y = ref.refPos.y + (ref.height - (float)f.tex->height) / 2.0f;
156 break;
157 }
158
160 glCompDrawText(f, x, y);
161}
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
Definition alloc.h:101
#define parent(i)
Definition closest.c:75
#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
static void print_bitmap_string(void *font, char *s)
Definition glcompfont.c:23
void glCompDrawText3D(glCompFont f, float x, float y, double z, float w, float h)
Definition glcompfont.c:111
void glCompDrawText(glCompFont f, double x, double y)
Definition glcompfont.c:130
glCompFont glNewFontFromParent(glCompObj *o, const char *text)
Definition glcompfont.c:72
void glDeleteFont(glCompFont *f)
Definition glcompfont.c:40
void glCompRenderText(glCompFont f, glCompObj *parentObj)
Definition glcompfont.c:136
void glprintfglut(void *font, float xpos, float ypos, float zpos, char *bf)
Definition glcompfont.c:33
glCompFont glNewFont(glCompSet *s, const char *text, glCompColor *c, char *fontdesc, int fs, bool is2D)
Definition glcompfont.c:48
void glCompDeleteTexture(glCompTex *t)
glCompTex * glCompSetAddNewTexLabel(glCompSet *s, char *def, int fs, const char *text, bool is2D)
void glCompSetColor(glCompColor c)
Definition glutils.c:281
void free(void *)
node NULL
Definition grammar.y:181
static int z
$2 font
Definition htmlparse.y:294
glCompPoint pos
Definition glcompdefs.h:164
void * parent
Definition glcompdefs.h:172
glCompPoint refPos
Definition glcompdefs.h:165
glCompSet * compset
Definition glcompdefs.h:171
glCompColor color
Definition glcompdefs.h:140
glCompTex * tex
Definition glcompdefs.h:143
char * fontdesc
Definition glcompdefs.h:139
glCompJustify justify
Definition glcompdefs.h:145
glCompHJustify HJustify
Definition glcompdefs.h:101
glCompVJustify VJustify
Definition glcompdefs.h:100
object prototype
Definition glcompdefs.h:184
glCompCommon common
Definition glcompdefs.h:185
uint32_t id
Definition glcompdefs.h:124
unsigned char * data
Definition glcompdefs.h:132
Definition grammar.c:90