summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/pdftexdir/writeenc.c
diff options
context:
space:
mode:
authorMartin Schröder <martin@oneiros.de>2006-12-26 23:37:34 +0000
committerMartin Schröder <martin@oneiros.de>2006-12-26 23:37:34 +0000
commit812aa90acbef4930ae356ab194f3f2a8f573f6e4 (patch)
treea1b8b3d895238994c60580df9e6f0619b2034923 /Build/source/texk/web2c/pdftexdir/writeenc.c
parente3bba99884ce591c9485122e96fff7071fc7c112 (diff)
Import pdftex 1.40-rc4, which also changes the signature of
print_version_and_exit, and adds a new library (libs/obsdcompat). git-svn-id: svn://tug.org/texlive/trunk@2959 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/pdftexdir/writeenc.c')
-rw-r--r--Build/source/texk/web2c/pdftexdir/writeenc.c206
1 files changed, 122 insertions, 84 deletions
diff --git a/Build/source/texk/web2c/pdftexdir/writeenc.c b/Build/source/texk/web2c/pdftexdir/writeenc.c
index 7963403ec7e..5547e3f7cb0 100644
--- a/Build/source/texk/web2c/pdftexdir/writeenc.c
+++ b/Build/source/texk/web2c/pdftexdir/writeenc.c
@@ -17,119 +17,156 @@ You should have received a copy of the GNU General Public License
along with pdfTeX; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeenc.c#13 $
+$Id: writeenc.c,v 1.3 2005/12/26 14:20:13 hahe Exp hahe $
-source code indentation by "indent -kr -nut"
*/
#include "ptexlib.h"
-#include "avlstuff.h"
-static const char perforce_id[] =
- "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeenc.c#13 $";
+/**********************************************************************/
+/* All encoding entries go into AVL tree for fast search by name. */
+
+struct avl_table *fe_tree = NULL;
-void read_enc(enc_entry * e)
+/* AVL sort fe_entry into fe_tree by name */
+
+static int comp_fe_entry(const void *pa, const void *pb, void *p)
{
- assert(e != NULL);
- if (e->loaded)
- return;
- load_enc(e->name, e->glyph_names);
- e->loaded = true;
+ return strcmp(((const fe_entry *) pa)->name, ((const fe_entry *) pb)->name);
}
-/* write_enc is used to write either external encoding (given in map file) or
- * internal encoding (read from the font file); when glyph_names is NULL
- * the 2nd argument is a pointer to the encoding entry; otherwise the 3rd is
- * the object number of the Encoding object
- */
-void write_enc(char **glyph_names, enc_entry * e, integer eobjnum)
+fe_entry *new_fe_entry()
{
- boolean is_notdef;
- int i;
- char **g;
- if (glyph_names == NULL) {
- assert(e != NULL);
- if (e->objnum != 0) /* the encoding has been written already */
- return;
- pdfnewdict(0, 0);
- e->objnum = objptr;
- g = e->glyph_names;
- } else {
- pdfbegindict(eobjnum);
- g = glyph_names;
+ fe_entry *fe;
+ fe = xtalloc(1, fe_entry);
+ fe->name = NULL;
+ fe->fe_objnum = 0;
+ fe->glyph_names = NULL; /* encoding file not yet read in */
+ fe->tx_tree = NULL;
+ return fe;
+}
+
+fe_entry *lookup_fe_entry(char *s)
+{
+ fe_entry fe;
+ assert(s != NULL);
+ fe.name = s;
+ if (fe_tree == NULL) {
+ fe_tree = avl_create(comp_fe_entry, NULL, &avl_xallocator);
+ assert(fe_tree != NULL);
}
- pdf_printf("/Type /Encoding\n/Differences [ 0 /%s", g[0]);
- is_notdef = (g[0] == notdef);
- for (i = 1; i <= MAX_CHAR_CODE; i++) {
- if (g[i] == notdef) {
- if (!is_notdef) {
- pdf_printf(" %i/%s", i, notdef);
- is_notdef = true;
- }
- } else {
- if (is_notdef) {
- pdf_printf(" %i", i);
- is_notdef = false;
- }
- pdf_printf("/%s", g[i]);
- }
+ return (fe_entry *) avl_find(fe_tree, &fe);
+}
+
+void register_fe_entry(fe_entry * fe)
+{
+ void **aa;
+ if (fe_tree == NULL) {
+ fe_tree = avl_create(comp_fe_entry, NULL, &avl_xallocator);
+ assert(fe_tree != NULL);
}
- pdf_puts("]\n");
- pdfenddict();
+ assert(fe != NULL);
+ assert(fe->name != NULL);
+ assert(lookup_fe_entry(fe->name) == NULL); /* encoding not yet registered */
+ aa = avl_probe(fe_tree, fe);
+ assert(aa != NULL);
}
-/**********************************************************************/
-/* All encoding entries go into AVL tree for fast search by name. */
+fe_entry *get_fe_entry(char *s)
+{
+ fe_entry *fe;
+ if ((fe = lookup_fe_entry(s)) == NULL) {
+ fe = new_fe_entry();
+ fe->name = s;
+ fe->glyph_names = load_enc_file(s);
+ register_fe_entry(fe);
+ }
+ return fe;
+}
-struct avl_table *enc_tree = NULL;
+/**********************************************************************/
-/* AVL sort enc_entry into enc_tree by name */
+void epdf_write_enc(char **glyph_names, integer fe_objnum)
+{
+ int i, i_old;
+ assert(glyph_names != NULL);
+ assert(fe_objnum != 0);
+ pdfbegindict(fe_objnum, 1);
+ pdf_puts("/Type /Encoding\n");
+ pdf_printf("/Differences [");
+ for (i = 0, i_old = -2; i < 256; i++)
+ if (glyph_names[i] != notdef) {
+ if (i == i_old + 1) /* no gap */
+ pdf_printf("/%s", glyph_names[i]);
+ else {
+ if (i_old == -2)
+ pdf_printf("%i/%s", i, glyph_names[i]);
+ else
+ pdf_printf(" %i/%s", i, glyph_names[i]);
+ }
+ i_old = i;
+ }
+ pdf_puts("]\n");
+ pdfenddict();
+}
-static int comp_enc_entry(const void *pa, const void *pb, void *p)
+void write_enc(char **glyph_names, struct avl_table *tx_tree, integer fe_objnum)
{
- return strcmp(((const enc_entry *) pa)->name,
- ((const enc_entry *) pb)->name);
+ int i_old, *p;
+ struct avl_traverser t;
+ assert(glyph_names != NULL);
+ assert(tx_tree != NULL);
+ assert(fe_objnum != 0);
+ pdfbegindict(fe_objnum, 1);
+ pdf_puts("/Type /Encoding\n");
+ pdf_printf("/Differences [");
+ avl_t_init(&t, tx_tree);
+ for (i_old = -2, p = (int *) avl_t_first(&t, tx_tree); p != NULL;
+ p = (int *) avl_t_next(&t)) {
+ if (*p == i_old + 1) /* no gap */
+ pdf_printf("/%s", glyph_names[*p]);
+ else {
+ if (i_old == -2)
+ pdf_printf("%i/%s", *p, glyph_names[*p]);
+ else
+ pdf_printf(" %i/%s", *p, glyph_names[*p]);
+ }
+ i_old = *p;
+ }
+ pdf_puts("]\n");
+ pdfenddict();
}
-enc_entry *add_enc(char *s)
+void write_fontencoding(fe_entry * fe)
{
- int i;
- enc_entry tmp, *p;
- void **aa;
+ assert(fe != NULL);
+ write_enc(fe->glyph_names, fe->tx_tree, fe->fe_objnum);
+}
- assert(s != NULL);
- if (enc_tree == NULL) {
- enc_tree = avl_create(comp_enc_entry, NULL, &avl_xallocator);
- assert(enc_tree != NULL);
- }
- tmp.name = s;
- p = (enc_entry *) avl_find(enc_tree, &tmp);
- if (p != NULL) /* encoding already registered */
- return p;
- p = xtalloc(1, enc_entry);
- p->loaded = false;
- p->name = xstrdup(s);
- p->objnum = 0;
- p->glyph_names = xtalloc(MAX_CHAR_CODE + 1, char *);
- for (i = 0; i <= MAX_CHAR_CODE; i++)
- p->glyph_names[i] = (char *) notdef;
- aa = avl_probe(enc_tree, p);
- assert(aa != NULL);
- return p;
+void write_fontencodings()
+{
+ fe_entry *fe;
+ struct avl_traverser t;
+ if (fe_tree == NULL)
+ return;
+ avl_t_init(&t, fe_tree);
+ for (fe = (fe_entry *) avl_t_first(&t, fe_tree); fe != NULL;
+ fe = (fe_entry *) avl_t_next(&t))
+ if (fe->fe_objnum != 0)
+ write_fontencoding(fe);
}
/**********************************************************************/
/* cleaning up... */
-static void destroy_enc_entry(void *pa, void *pb)
+static void destroy_fe_entry(void *pa, void *pb)
{
- enc_entry *p;
+ fe_entry *p;
int i;
-
- p = (enc_entry *) pa;
+ p = (fe_entry *) pa;
xfree(p->name);
if (p->glyph_names != NULL)
- for (i = 0; i <= MAX_CHAR_CODE; i++)
+ for (i = 0; i < 256; i++)
if (p->glyph_names[i] != notdef)
xfree(p->glyph_names[i]);
xfree(p->glyph_names);
@@ -138,8 +175,9 @@ static void destroy_enc_entry(void *pa, void *pb)
void enc_free()
{
- if (enc_tree != NULL)
- avl_destroy(enc_tree, destroy_enc_entry);
+ if (fe_tree != NULL)
+ avl_destroy(fe_tree, destroy_fe_entry);
+ fe_tree = NULL;
}
/**********************************************************************/