1 /* Public domain */
2
3 #define VG_TEXT_MAX 256
4 #define VG_TEXT_MAX_PTRS 32
5 #define VG_FONT_FACE_MAX 32
6 #define VG_FONT_STYLE_MAX 16
7 #define VG_FONT_SIZE_MIN 4
8 #define VG_FONT_SIZE_MAX 48
9
10 typedef struct vg_text {
11 struct vg_node _inherit;
12 VG_Point *p1, *p2; /* Position line */
13 enum vg_alignment align; /* Text alignment around line */
14
15 char fontFace[VG_FONT_FACE_MAX]; /* Font face */
16 int fontSize; /* Font size */
17 Uint fontFlags; /* Font flags */
18 #define VG_TEXT_BOLD 0x01 /* Bold style */
19 #define VG_TEXT_ITALIC 0x02 /* Italic style */
20 #define VG_TEXT_UNDERLINE 0x04 /* Underlined */
21 #define VG_TEXT_SCALED 0x08 /* Try to scale the text */
22
23 char text[VG_TEXT_MAX]; /* Text or format string */
24 AG_List *args; /* Text arguments */
25 int *argSizes; /* Sizes of format strings in text */
26
27 void *vsObj; /* Object for $(foo) expansion */
28 } VG_Text;
29
30 #define VGTEXT(p) ((VG_Text *)(p))
31
32 __BEGIN_DECLS
33 extern VG_NodeOps vgTextOps;
34
35 void VG_TextString(VG_Text *, const char *);
36 void VG_TextPrintf(VG_Text *, const char *, ...);
37
38 static __inline__ VG_Text *
VG_TextNew(void * pNode,VG_Point * p1,VG_Point * p2)39 VG_TextNew(void *pNode, VG_Point *p1, VG_Point *p2)
40 {
41 VG_Text *vt;
42
43 vt = (VG_Text *)AG_Malloc(sizeof(VG_Text));
44 VG_NodeInit(vt, &vgTextOps);
45 vt->p1 = p1;
46 vt->p2 = p2;
47 VG_AddRef(vt, p1);
48 VG_AddRef(vt, p2);
49 VG_NodeAttach(pNode, vt);
50 return (vt);
51 }
52
53 static __inline__ void
VG_TextAlignment(VG_Text * vt,enum vg_alignment align)54 VG_TextAlignment(VG_Text *vt, enum vg_alignment align)
55 {
56 VG_Lock(VGNODE(vt)->vg);
57 vt->align = align;
58 VG_Unlock(VGNODE(vt)->vg);
59 }
60 static __inline__ void
VG_TextFontFace(VG_Text * vt,const char * face)61 VG_TextFontFace(VG_Text *vt, const char *face)
62 {
63 VG_Lock(VGNODE(vt)->vg);
64 AG_Strlcpy(vt->fontFace, face, sizeof(vt->fontFace));
65 VG_Unlock(VGNODE(vt)->vg);
66 }
67 static __inline__ void
VG_TextFontSize(VG_Text * vt,int size)68 VG_TextFontSize(VG_Text *vt, int size)
69 {
70 VG_Lock(VGNODE(vt)->vg);
71 vt->fontSize = size;
72 VG_Unlock(VGNODE(vt)->vg);
73 }
74 static __inline__ void
VG_TextFontFlags(VG_Text * vt,Uint flags)75 VG_TextFontFlags(VG_Text *vt, Uint flags)
76 {
77 VG_Lock(VGNODE(vt)->vg);
78 vt->fontFlags = flags;
79 VG_Unlock(VGNODE(vt)->vg);
80 }
81 static __inline__ void
VG_TextSubstObject(VG_Text * vt,void * obj)82 VG_TextSubstObject(VG_Text *vt, void *obj)
83 {
84 VG_Lock(VGNODE(vt)->vg);
85 vt->vsObj = obj;
86 VG_Unlock(VGNODE(vt)->vg);
87 }
88 __END_DECLS
89