2006-12-03 Dimitris Glezos <dimitris@glezos.com>
[dia.git] / lib / ps-utf8.h
blob3a3df90061e33d0c63b0a90f3690af0356dab352
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * ps-utf8.h: builds custom Postscript encodings to write arbitrary utf8
5 * strings and have the device understand what's going on.
6 * Copyright (C) 2001 Cyrille Chepelov <chepelov@calixo.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #ifndef PS_UTF8_H
24 #define PS_UTF8_H
26 #include <config.h>
27 #include <glib.h>
29 #include "diatypes.h"
31 #define PSEPAGE_BEGIN 32
32 #define PSEPAGE_SIZE (256-PSEPAGE_BEGIN)
34 struct _PSFontDescriptor {
35 const gchar *face; /* LE */
36 const gchar *name; /* LE */
37 const PSEncodingPage *encoding; /* DNLE */
38 int encoding_serial_num; /* if encoding->serial_num > this, we have to
39 re-emit the font. If it's negative,
40 the font has never been emitted. */
41 };
43 /* "defined_fonts" cache is simply a dictionary (g_hash_table):
44 ("face-e%d-%f" % (encoding_page_#,size)) --> font descriptor
48 struct _PSEncodingPage {
49 const gchar *name; /* LE. */
50 int page_num;
51 int serial_num;
52 int last_realized;
53 int entries;
54 GHashTable *backpage; /* LE(unichar -> char) */
55 gunichar page[PSEPAGE_SIZE];
58 struct _PSUnicoder {
59 gpointer usrdata;
60 const PSUnicoderCallbacks *callbacks;
62 const gchar *face;
63 float size;
64 float current_size; /* might lag a little... */
65 PSFontDescriptor *current_font; /* DNLE */
67 GHashTable *defined_fonts; /* LE(DNLE name -> LE PSFontDescriptor *fd) */
68 GHashTable *unicode_to_page; /* LE(unicode -> DNLE PSEncodingPage *ep) */
69 GSList *encoding_pages; /* LE(LE PSEncodingPage) */
70 PSEncodingPage *last_page; /* DNLE */
71 const PSEncodingPage *current_encoding; /* DNLE */
74 typedef void (*DestroyPSFontFunc)(gpointer usrdata, const gchar *fontname);
75 typedef void (*BuildPSEncodingFunc)(gpointer usrdata,
76 const gchar *name,
77 const gunichar table[PSEPAGE_SIZE]);
78 /* note: the first $PSEPAGE_BEGIN will always be /.notdef, likewise
79 for ( and ) */
80 typedef void (*BuildPSFontFunc)(gpointer usrdata,
81 const gchar *name,
82 const gchar *face,
83 const gchar *encoding_name);
84 /* must definefont a font under "fontname", with the "encname" encoding
85 (already defined). */
86 typedef void (*SelectPSFontFunc)(gpointer usrdata,
87 const gchar *fontname,
88 float size);
89 /* must select (setfont) an already found and defined font. */
90 typedef void (*ShowStringFunc)(gpointer usrdata, const gchar *string);
91 /* typically, does "(string) show" (but can do other things).
92 string is guaranteed to not have escaping issues. */
93 typedef void (*GetStringWidthFunc)(gpointer usrdata, const gchar *string,
94 gboolean first);
95 /* gets the string width on the PS stack. if !first, adds it to the previous
96 element of the stack. */
98 struct _PSUnicoderCallbacks {
99 DestroyPSFontFunc destroy_ps_font;
100 BuildPSEncodingFunc build_ps_encoding;
101 BuildPSFontFunc build_ps_font;
102 SelectPSFontFunc select_ps_font;
103 ShowStringFunc show_string;
104 GetStringWidthFunc get_string_width;
108 extern PSUnicoder *ps_unicoder_new(const PSUnicoderCallbacks *psucbk,
109 gpointer usrdata);
110 extern void ps_unicoder_destroy(PSUnicoder *psu);
112 extern void psu_set_font_face(PSUnicoder *psu, const gchar *face, float size);
113 /* just stores the font face and size we'll later use */
115 extern void psu_check_string_encodings(PSUnicoder *psu,
116 const char *utf8_string);
117 /* appends what's going to be needed in the encoding tables */
119 extern void psu_show_string(PSUnicoder *psu,
120 const char *utf8_string);
121 /* shows the string, asking back for as many font and encoding manipulations
122 as necessary. */
123 extern void psu_get_string_width(PSUnicoder *psu,
124 const char *utf8_string);
125 /* puts the string width on the PS stack. */
127 extern const char *unicode_to_ps_name(gunichar val);
128 /* returns "uni1234", or a special Adobe entity name. */
131 #endif /* !PS_UTF8_H */