--- dvipdfm/Makefile.in.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/Makefile.in Sat Oct 6 02:32:25 2001 @@ -21,17 +21,19 @@ src=pdfdev.c pdfdoc.c dvi.c mfileio.c mem.c jpeg.c numbers.c pdfobj.c \ pdfparse.c pdfspecial.c tfm.c type1.c dvipdfm.c epdf.c vf.c \ t1crypt.c pkfont.c tpic.c thumbnail.c pngimage.c ebb.c htex.c \ - mpost.c psimage.c psspecial.c colorsp.c encodings.c @TTF_OPT@ ttf.c + mpost.c psimage.c psspecial.c colorsp.c encodings.c @TTF_OPT@ ttf.c \ + type0.c cid.c cidbase.c objects=pdfdev.o pdfdoc.o dvi.o mfileio.o mem.o jpeg.o numbers.o pdfobj.o \ pdfparse.o pdfspecial.o tfm.o type1.o dvipdfm.o epdf.o vf.o \ t1crypt.o pkfont.o tpic.o thumbnail.o pngimage.o htex.o \ - mpost.o psimage.o psspecial.o colorsp.o encodings.o @TTF_OPT@ ttf.o + mpost.o psimage.o psspecial.o colorsp.o encodings.o @TTF_OPT@ ttf.o \ + type0.o cid.o cidbase.o manpages=dvipdfm.1 eobjects=ebb.o jpeg.o pdfobj.o mem.o mfileio.o numbers.o pdfparse.o \ pngimage.o encodings=ot1.enc ot1alt.enc ot1r.enc -mapfiles=cmr.map psbase14.map lw35urw.map lw35urwa.map +mapfiles=cmr.map psbase14.map lw35urw.map lw35urwa.map cid.map check default all: $(programs) ebb: $(eobjects) Makefile $(CC) -o ebb $(eobjects) $(LDFLAGS) $(LIBS) --- dvipdfm/cidbase.c.orig Sat Oct 6 02:38:30 2001 +++ dvipdfm/cidbase.c Sat Oct 6 02:32:25 2001 @@ -0,0 +1,205 @@ +#include +#include +#include "mem.h" +#include "error.h" +#include "pdfobj.h" +#include "pdfparse.h" +#include "type0.h" +#include "cid.h" +#include "cid_basefont.h" +#include "cidbase.h" + +static unsigned char verbose = 0; + +void cidbase_set_verbose(void) +{ + if(verbose<255) verbose += 1; +} + +static void cidbase_start_font_descriptor (struct a_cid_font *cid) +{ + pdf_obj *tmp1; + char *start, *end; + int base_id; + +#ifdef MEM_DEBUG +MEM_START +#endif + cid->descriptor = pdf_new_dict(); + base_id = cid->base_id; + + pdf_add_dict (cid->descriptor, + pdf_new_name ("Type"), + pdf_new_name ("FontDescriptor")); + pdf_add_dict (cid->descriptor, + pdf_new_name ("CapHeight"), + pdf_new_number (cid_basefont[base_id].capheight)); + pdf_add_dict (cid->descriptor, + pdf_new_name ("Ascent"), + pdf_new_number (cid_basefont[base_id].ascent)); + pdf_add_dict (cid->descriptor, + pdf_new_name ("Descent"), + pdf_new_number (cid_basefont[base_id].descent)); + + start = (char *) cid_basefont[base_id].bbox; + end = start+strlen(cid_basefont[base_id].bbox); + tmp1 = parse_pdf_array (&start, end); + pdf_add_dict (cid->descriptor, pdf_new_name ("FontBBox"), tmp1); + + pdf_add_dict (cid->descriptor, + pdf_new_name ("FontName"), + pdf_new_name (cid_basefont[base_id].fontname)); + + pdf_add_dict (cid->descriptor, + pdf_new_name ("ItalicAngle"), + pdf_new_number(cid_basefont[base_id].italic)); + pdf_add_dict (cid->descriptor, + pdf_new_name ("StemV"), + pdf_new_number(cid_basefont[base_id].stemv)); + pdf_add_dict (cid->descriptor, + pdf_new_name ("Flags"), + pdf_new_number(cid_basefont[base_id].flags)); + + /* optional entries */ + if( cid_basefont[base_id].xheight ) { + pdf_add_dict (cid->descriptor, + pdf_new_name ("XHeight"), + pdf_new_number(cid_basefont[base_id].xheight)); + } + if( cid_basefont[base_id].avgw ) { + pdf_add_dict (cid->descriptor, + pdf_new_name ("AvgWidth"), + pdf_new_number(cid_basefont[base_id].avgw)); + } + if( cid_basefont[base_id].leading ) { + pdf_add_dict (cid->descriptor, + pdf_new_name ("Leading"), + pdf_new_number(cid_basefont[base_id].leading)); + } + if( cid_basefont[base_id].maxw ) { + pdf_add_dict (cid->descriptor, + pdf_new_name ("MaxWidth"), + pdf_new_number(cid_basefont[base_id].maxw)); + } + if( cid_basefont[base_id].missw ) { + pdf_add_dict (cid->descriptor, + pdf_new_name ("MissingWidth"), + pdf_new_number(cid_basefont[base_id].missw)); + } + if( cid_basefont[base_id].stemh ) { + pdf_add_dict (cid->descriptor, + pdf_new_name ("StemH"), + pdf_new_number(cid_basefont[base_id].stemh)); + } + if( cid_basefont[base_id].charset ) { + pdf_add_dict (cid->descriptor, + pdf_new_name ("CharSet"), + pdf_new_string (cid_basefont[base_id].charset, + strlen(cid_basefont[base_id].charset))); + } + if (cid_basefont[base_id].style) { + start = (char *) cid_basefont[base_id].style; + end = start+strlen(cid_basefont[base_id].style); + tmp1 = parse_pdf_object (&start, end); + pdf_add_dict (cid->descriptor, pdf_new_name ("Style"), tmp1); + } + +#ifdef MEM_DEBUG +MEM_END +#endif /* MEM_DEBUG */ + return; +} + +int cidbase_get_id (const char *map_name) +{ + struct a_cid_font *cid; + int i, base_id; + pdf_obj *font_resource, *tmp1; + char *start, *end; + +#ifdef MEM_DEBUG +MEM_START +#endif + for (i=0; icid_name = NEW (strlen(map_name)+1, char); + cid->fontname = NEW (strlen(map_name)+1, char); + strcpy (cid->cid_name, map_name); + strcpy (cid->fontname, map_name); + cid->base_id = base_id; + + cidbase_start_font_descriptor(cid); + font_resource = pdf_new_dict (); + pdf_add_dict (font_resource, + pdf_new_name ("Type"), + pdf_new_name ("Font")); + pdf_add_dict (font_resource, + pdf_new_name ("Subtype"), + pdf_new_name (cid_basefont[base_id].subtype)); + pdf_add_dict (font_resource, + pdf_new_name ("BaseFont"), + pdf_new_name (cid->fontname)); + pdf_add_dict (font_resource, + pdf_new_name ("FontDescriptor"), + pdf_ref_obj(cid->descriptor)); + + cid_add_system_info(font_resource, cid_basefont[base_id].cc_name); + + /* optional entries */ + if (cid_basefont[base_id].dw) { + pdf_add_dict (font_resource, + pdf_new_name ("DW"), + pdf_new_number (cid_basefont[base_id].dw)); + } + if (cid_basefont[base_id].w) { + start = (char *) cid_basefont[base_id].w; + end = start+strlen(cid_basefont[base_id].w); + tmp1 = parse_pdf_array (&start, end); + pdf_add_dict (font_resource, pdf_new_name ("W"), tmp1); + } + if (cid_basefont[base_id].dw2) { + start = (char *) cid_basefont[base_id].dw2; + end = start+strlen(cid_basefont[base_id].dw2); + tmp1 = parse_pdf_array (&start, end); + pdf_add_dict (font_resource, pdf_new_name ("DW2"), tmp1); + } + if (cid_basefont[base_id].w2) { + start = (char *) cid_basefont[base_id].w2; + end = start+strlen(cid_basefont[base_id].w2); + tmp1 = parse_pdf_array (&start, end); + pdf_add_dict (font_resource, pdf_new_name ("W2"), tmp1); + } + + cid->indirect = pdf_ref_obj(font_resource); + /* + We are not embedding (subsetted) font, + all information are already given. + Everything has been done. Flush & release the content ! + */ + pdf_release_obj(cid->descriptor); + pdf_release_obj (font_resource); + cid->descriptor = NULL; + +#ifdef MEM_DEBUG +MEM_END +#endif /* MEM_DEBUG */ + return 1; +} + +void do_cidbase (int id) +{ + /* nothing to be done */ +} + +void cidbase_release (int id) +{ + /* nothing to be done */ +} --- dvipdfm/cidbase.h.orig Sat Oct 6 02:38:30 2001 +++ dvipdfm/cidbase.h Sat Oct 6 02:32:25 2001 @@ -0,0 +1,8 @@ +/* cid.h */ +#ifndef _CIDBASE_H_ +#define _CIDBASE_H_ +extern void cidbase_set_verbose(void); +extern int cidbase_get_id (const char *map_name); +extern void do_cidbase (int cid_id); +extern void cidbase_release (int cid_id); +#endif /* _CIDBASE_H_ */ --- dvipdfm/cid.c.orig Sat Oct 6 02:38:30 2001 +++ dvipdfm/cid.c Sat Oct 6 02:32:25 2001 @@ -0,0 +1,194 @@ +/* CID-keyed Font */ +#include "config.h" +#include +#include +#include "mem.h" +#include "error.h" +#include "pdfobj.h" +#include "numbers.h" +#include "pdflimits.h" +#include "type0.h" +#include "cidbase.h" +#include "cid.h" + +static unsigned num_cids = 0, max_cids = 0; +static struct a_cid_font *cids = NULL; +static unsigned char verbose = 0; + +void cid_set_verbose(void) +{ + if (verbose < 255) { + verbose += 1; + } + cidbase_set_verbose(); +} + +/* Character Collection and CMap */ +static const struct { + char *registry; + char *ordering; + int supplement; +} cid_cc_names[4] = { + {"Adobe", "GB1", 0}, /* not supportd */ + {"Adobe", "CNS1", 1}, /* not supportd */ + {"Adobe", "Japan1", 2}, /* supplement = 1 ? */ + {"Adobe", "Korea1", 1}, /* not supportd */ +}; + +void cid_add_system_info(pdf_obj *dict, int cc) +{ + pdf_obj *systeminfo; + char *reg, *ord; + int sup; + + if (cc < 0 || cc > CC_KOREAN) { + ERROR("invalid Character Collection ID"); + } else { + systeminfo = pdf_new_dict (); + + reg = cid_cc_names[cc].registry; + ord = cid_cc_names[cc].ordering; + sup = cid_cc_names[cc].supplement; + + pdf_add_dict (systeminfo, + pdf_new_name ("Registry"), + pdf_new_string (reg, strlen(reg))); + pdf_add_dict (systeminfo, + pdf_new_name ("Ordering"), + pdf_new_string (ord, strlen(ord))); + pdf_add_dict (systeminfo, + pdf_new_name ("Supplement"), + pdf_new_number (sup)); + + pdf_add_dict (dict, + pdf_new_name ("CIDSystemInfo"), + systeminfo); + } + return; +} + +int cid_find_parent(const char *map_name, char *encoding) +{ + int i, cid_id, parent; + char *enc_name; + if ((cid_id = cid_is_known_font(map_name)) >= 0) { + for (i=0;i=0 && cid_id= max_cids) { + max_cids += MAX_FONTS; + cids = RENEW (cids, max_cids, struct a_cid_font); + } + + if (verbose>3) fprintf(stderr, "new cid font (id: %d)\n", num_cids); + /* descriptor and fontfile should not be here ? */ + cid_font = &(cids[num_cids]); + cids[num_cids].fontname = NULL; + cids[num_cids].cid_name = NULL; + cids[num_cids].direct = NULL; /* fixme */ + cids[num_cids].indirect = NULL; + cids[num_cids].descriptor = NULL; + cids[num_cids].fontfile = NULL; /* fixme */ + cids[num_cids].num_parents = 0; + cids[num_cids].base_id = -1; + cids[num_cids].cc = CC_JAPANESE; /* fixme */ + num_cids += 1; + + return cid_font; +} + +/* returns PostScript name */ +char *cid_fontname (int cid_id) +{ + if (cid_id >= 0 && cid_id < num_cids) { + return cids[cid_id].fontname; + } else { + return NULL; + } +} + +/* fixme */ +int cid_is_known_font (const char *map_name) +{ + int i; + + for (i=0; i3) fprintf(stderr, "a CID font\n"); + } else { + if(verbose>3) fprintf(stderr, "not a CID font\n"); + result = -1; + } + } + +#ifdef MEM_DEBUG + MEM_END +#endif /* MEM_DEBUG */ + return result; +} + +void cid_flush_all (void) +{ + int i; + + for (i=0; i1) fprintf(stderr, "(CID:%s)", cid_fontname(i)); + do_cidbase(i); + cidbase_release(i); + if (cids[i].descriptor) pdf_release_obj (cids[i].descriptor); + if (cids[i].direct) pdf_release_obj (cids[i].direct); /* fixme */ + if (cids[i].indirect) pdf_release_obj (cids[i].indirect); + if (cids[i].fontfile) pdf_release_obj (cids[i].fontfile); /* fixme */ + if (cids[i].cid_name) RELEASE (cids[i].cid_name); + if (cids[i].fontname) RELEASE (cids[i].fontname); + } + if (cids) RELEASE(cids); +} --- dvipdfm/cid.h.orig Sat Oct 6 02:38:30 2001 +++ dvipdfm/cid.h Sat Oct 6 02:32:25 2001 @@ -0,0 +1,46 @@ +/* cid.h */ +#ifndef _CID_H_ +#define _CID_H_ +#include "pdfobj.h" +/* + Adobe Predefined CMaps + Only CC_JAPANESE is supprted. +*/ +#define CC_SIMPLIFIED_CHINESE 0 +#define CC_TRADITIONAL_CHINESE 1 +#define CC_JAPANESE 2 +#define CC_KOREAN 3 + +/* Flags */ +#define FIXEDWIDTH (1 << 0) /* Fixed-width font */ +#define SERIF (1 << 1) /* Serif font */ +#define SYMBOLIC (1 << 2) /* Symbolic font */ +#define SCRIPT (1 << 3) /* Script font */ +#define STANDARD (1 << 5) /* Uses the Adobe Standard Roman Character Set */ +#define ITALIC (1 << 6) /* Italic */ +#define ALLCAP (1 << 16) /* All-cap font */ +#define SMALLCAP (1 << 17) /* Small-cap font */ +#define FOCEBOLD (1 << 18) /* Force bold at small text sizes */ + +#define CID_MAX_PARENT 8 +struct a_cid_font +{ + char *fontname; /* PostScript font name */ + char *cid_name; /* this is mapname */ + pdf_obj *direct, *indirect, *descriptor, *fontfile; /* fixme */ + int base_id; /* identifier of predefined CID font, see cid_basefont.h */ + int parent[CID_MAX_PARENT]; /* parent type0 font */ + int num_parents; + int cc; /* character collection */ +}; + +extern void cid_set_verbose(void); +extern void cid_add_system_info(pdf_obj *dict, int cc); +extern struct a_cid_font *new_cid_font(void); +extern int cid_is_known_font (const char *map_name); +extern int cid_find_parent(const char *map_name, char *encoding); +extern pdf_obj *cid_call_descendant(int type0_id, int cid_id); +extern int cid_get_id (const char *map_name); +extern char *cid_fontname (int cid_id); +extern void cid_flush_all (void); +#endif /* _CID_H_ */ --- dvipdfm/cid.map.orig Sat Oct 6 02:38:30 2001 +++ dvipdfm/cid.map Sat Oct 6 02:32:25 2001 @@ -0,0 +1,15 @@ +%% PostScript 'standard' font +%% Ryumin-Light and GothicBBB-Medium will not be embedded. +%% see cid_basefont.h for predefined base/core fonts. +rml none Ryumin-Light +gbm none GothicBBB-Medium +rmlv none Ryumin-Light +gbmv none GothicBBB-Medium + +%% PDF 'core' font +%% HeiseiMin-W3 and HeiseiKakuGo-W5 will not be embedded also. +%% see cid_basefont.h for predefined base/core fonts. +%rml none HeiseiMin-W3 +%gbm none HeiseiKakuGo-W5 +%rmlv none HeiseiMin-W3 +%gbmv none HeiseiKakuGo-W5 --- dvipdfm/cid_basefont.h.orig Sat Oct 6 02:38:30 2001 +++ dvipdfm/cid_basefont.h Sat Oct 6 02:32:25 2001 @@ -0,0 +1,179 @@ +#ifndef _CID_BASEFONT_H_ +#define _CID_BASEFONT_H_ + +/* PDF object xxx is treated as yyy in this file */ +#define NAME char * +#define INT double +#define ARRAY char * +#define STRING char * +#define DICTIONARY char * + +/* CID font embedding is not supported yet, so related stuff are omitted */ +typedef struct { + NAME fontname; /* PostScript Font Name, required */ + NAME subtype; /* Subtype, CIDType0 or CIDType2, required */ + int cc_name; /* Charcter Collection, required */ + INT ascent; /* Ascent, required */ + INT capheight; /* CapHeight, required */ + INT descent; /* Descent, required */ + INT flags; /* Flags, required */ + INT dw; /* DW (Default Width), optional */ + ARRAY w; /* W (Width array), optional */ + ARRAY dw2; /* DW2 (for vertical writing mode), optional */ + ARRAY w2; /* W2 (for vertical writing mode), optional */ + ARRAY bbox; /* FontBBox, required */ + INT italic; /* ItalicAngle, required */ + INT stemv; /* StemV, required */ + INT avgw; /* AvgWidth, optional */ + INT leading; /* Leading, optional */ + INT maxw; /* MaxWidth, optional */ + INT missw; /* MissingWidth, optional */ + INT stemh; /* StemH, optional */ + INT xheight; /* XHeight, optional */ + STRING charset; /* Charset, optional */ + DICTIONARY style; /* Style, optional */ +} cid_info; + +/* - Use of Style - + cited from PDF Reference Manual v. 1.1 + + The Style dictionary contains a set of key-value pairs that define + style attribute and value for the font. Currently only the Panose + key is defined. The value of the Panose key is the 12-byte string + containing the Family Class ID, Family SubClass ID, and 10 bytes for + the Panose classification number for the font. For additional details + on the Panose number see the TrueType 1.0 Font Files specification + from Microsoft. + + --- + Usage: + + /Style << /Panose (12-byte string) >> + + Note: + Acrobat Reader uses those numbers when substituting missing font. + + - Obtaining Family Class ID, Fimily SubClass ID, + and Panose Classification Number - + + TrueType: see OS/2 table + (TrueType font for MacOS may not have OS/2 table) +*/ + +/* - Subtypes - + CIDFontType0 - PostScript Type1 glyph data + CIDFontType2 - TrueType glyph data +*/ +#define TYPE0 "CIDFontType0" +#define TRUETYPE "CIDFontType2" + +/* Please correct me */ +/* + PDF core font for Japanese: + HeiseiMin-W3-Acro, HeiseiKakuGo-W5-Acro + PostScript "standard" font for Japanese: + Ryumin-Light, GothicBBB-Medium +*/ + +/* Should not use 0 to represent undefined INT values ... Please correct me */ +#define CID_LAST_BASEFONT 4 +const cid_info cid_basefont[CID_LAST_BASEFONT] = { + { + "HeiseiKakuGo-W5", /* FontName, required */ + TYPE0, /* Subtype, CIDFontType0 or CIDFontType2, required */ + CC_JAPANESE, /* Character Collection, required */ + 752, /* Ascend, required */ + 737, /* CapHeight, required */ + -221, /* Descend, required */ + SYMBOLIC, /* Font flags, required */ + 0, /* DW, optioanl, zero starnds for undefined */ + NULL, /* W, optional */ + NULL, /* DW2, optional */ + NULL, /* W2, optional */ + "[-92 -250 1010 922]", /* FontBBox, required */ + 0, /* ItalicAngle, required */ + 114, /* StemV, required */ + 0, /* AvgWidth, optional */ + 0, /* Leading, optional */ + 0, /* MaxWidth, optional */ + 0, /* MissingWidth, optional */ + 0, /* StemH, optional */ + 553, /* XHeight, optional */ + NULL, /* CharSet, optional */ + NULL /* Style, optional */ + }, + { + "HeiseiMin-W3", + TYPE0, + CC_JAPANESE, + 723, + 709, + -241, + SYMBOLIC+SERIF, /* 6, */ + 0, + NULL, + NULL, + NULL, + "[-123 -257 1001 910]", + 0, + 69, + 0, + 0, + 0, + 0, + 0, + 450, + NULL, + NULL + }, + { + "Ryumin-Light", + TYPE0, + CC_JAPANESE, + 723, + 709, + -241, + SYMBOLIC+SERIF, + 1000, + NULL, + NULL, + NULL, + "[-170 -331 1024 903]", + 0, + 69, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + "<< /Panose <010502020300000000000000> >>" + }, + { + "GothicBBB-Medium", + TYPE0, + CC_JAPANESE, + 752, + 737, + -271, + SYMBOLIC, + 1000, + NULL, + NULL, + NULL, + "[-174 -268 1001 944]", + 0, + 99, + 0, + 0, + 0, + 0, + 0, + 0, + NULL, + "<< /Panose <0801020b0500000000000000> >>" + } +}; + +#endif /* _CID_BASEFONT_H_ */ --- dvipdfm/config.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/config Sat Oct 6 02:32:25 2001 @@ -23,7 +23,7 @@ % D "/usr/local/bin/distill -quiet -pairs %i %o" % Set default paper size here -p letter +p a4 % The "g" option specifies the amount to "grow" annotations by % Many TeX macro pages set the annotation bounding box equal @@ -43,4 +43,5 @@ f lw35urw.map % Some use these names % f lw35urwa.map +f cid.map --- dvipdfm/dvicodes.h.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/dvicodes.h Sat Oct 6 02:32:25 2001 @@ -98,6 +98,7 @@ four byte magnification (multiplied by 1000) one byte unsigned comment length followed by comment. */ #define DVI_ID 2 /* ID Byte for current DVI file */ +#define DVIV_ID 3 /* with Ascii pTeX VW mode extension */ #define POST 248 /* Postamble- -- similar to preamble four byte pointer to final bop four byte numerator @@ -112,4 +113,5 @@ Version byte (same as preamble) Padded by four or more 223's to the end of the file. */ #define PADDING 223 +#define DIR 255 /* Ascii pTeX DIR command */ --- dvipdfm/dvi.c.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/dvi.c Sat Oct 6 02:32:25 2001 @@ -139,7 +139,7 @@ /* file_position now points to last non padding character or beginning of file */ if (dvi_file_size - current < 4 || - current == 0 || read_byte != DVI_ID) { + current == 0 || !(read_byte == DVI_ID || read_byte == DVIV_ID)) { fprintf (stderr, "DVI ID = %d\n", read_byte); invalid_signature(); } @@ -330,7 +330,7 @@ variables: */ struct dvi_registers { - SIGNED_QUAD h, v, w, x, y, z; + SIGNED_QUAD h, v, w, x, y, z, d; }; static struct dvi_registers dvi_state; @@ -343,6 +343,7 @@ { dvi_state.h = 0; dvi_state.v = 0; dvi_state.w = 0; dvi_state.x = 0; dvi_state.y = 0; dvi_state.z = 0; + dvi_state.d = 0; /* direction */ dvi_stack_depth = 0; current_font = -1; } @@ -410,12 +411,20 @@ void dvi_right (SIGNED_QUAD x) { - dvi_state.h += x; + if (!dvi_state.d) { + dvi_state.h += x; + } else { + dvi_state.v += x; + } } void dvi_down (SIGNED_QUAD y) { - dvi_state.v += y; + if (!dvi_state.d) { + dvi_state.v += y; + } else { + dvi_state.h -= y; + } } static void do_string (unsigned char *s, int len) @@ -455,7 +464,11 @@ } dvi_pop(); } - dvi_state.h += width; + if (!dvi_state.d) { + dvi_state.h += width; + } else { + dvi_state.v += width; + } } void dvi_set (SIGNED_QUAD ch) @@ -478,10 +491,14 @@ switch (p->type) { case PHYSICAL: if (ch > 255) { - ERROR ("Tried to set a multibyte character in a non-virtual font"); + unsigned char wch[2] = {'\0', '\0'}; + wch[0] = ch >> 8; + wch[1] = ch & 0xff; + dev_set_string (dvi_state.h, -dvi_state.v, wch, 2, width, p->font_id); + } else { + lch = (unsigned char) ch; + dev_set_string (dvi_state.h, -dvi_state.v, &lch, 1, width, p->font_id); } - lch = (unsigned char) ch; - dev_set_string (dvi_state.h, -dvi_state.v, &lch, 1, width, p->font_id); if (compute_boxes) { height = tfm_get_fw_height (p->tfm_id, ch); depth = tfm_get_fw_depth (p->tfm_id, ch); @@ -496,7 +513,11 @@ break; } } - dvi_state.h += width; + if (!dvi_state.d) { + dvi_state.h += width; + } else { + dvi_state.v += width; + } } void dvi_put (SIGNED_QUAD ch) @@ -516,10 +537,14 @@ string routine. The possibly multi-byte character must be converted to a single-byte string */ if (ch > 255) { - ERROR ("Tried to set a multibyte character in a non-virtual font"); + unsigned char wch[2] = {'\0', '\0'}; + wch[0] = ch >> 8; + wch[1] = ch & 0xff; + dev_set_string (dvi_state.h, -dvi_state.v, wch, 2, width, p->font_id); + } else { + lch = (unsigned char) ch; + dev_set_string (dvi_state.h, -dvi_state.v, &lch, 1, width, p->font_id); } - lch = (unsigned char) ch; - dev_set_string (dvi_state.h, -dvi_state.v, &lch, 1, width, p->font_id); if (compute_boxes) { height = tfm_get_fw_height (p->tfm_id, ch); depth = tfm_get_fw_depth (p->tfm_id, ch); @@ -539,8 +564,13 @@ void dvi_rule (SIGNED_QUAD width, SIGNED_QUAD height) { do_moveto (dvi_state.h, dvi_state.v); - dev_rule (dvi_state.h, -dvi_state.v, - width, height); + if (!dvi_state.d) { + dev_rule (dvi_state.h, -dvi_state.v, + width, height); + } else { /* right ? */ + dev_rule (dvi_state.h, -dvi_state.v-width, + height, width); + } } static void do_set1(void) @@ -608,6 +638,7 @@ } else ERROR ("dvi_pop: Tried to pop an empty stack"); do_moveto (dvi_state.h, dvi_state.v); + dev_set_wmode((int) dvi_state.d); } @@ -936,6 +967,13 @@ } dev_eop(); } + +static void do_dir(void) +{ + dvi_state.d = get_unsigned_byte (dvi_file); + dev_set_wmode((int) dvi_state.d); /* 0: horizontal, 1: vertical */ +} + /* Note to be absolutely certain that the string escape buffer doesn't hit its limit, FORMAT_BUF_SIZE should set to 4 times S_BUFFER_SIZE in pdfobj.c. Is there any application that genenerate words with @@ -1151,6 +1189,9 @@ case POST_POST: ERROR("Unexpected preamble or postamble in dvi file"); break; + case DIR: + do_dir(); + break; default: ERROR("Unexpected opcode or DVI file ended prematurely"); } @@ -1220,6 +1261,7 @@ dvi_push (); dvi_state.w = 0; dvi_state.x = 0; dvi_state.y = 0; dvi_state.z = 0; + /* do not reset dvi_state.d. */ if (num_saved_fonts < MAX_VF_NESTING) { saved_dvi_font[num_saved_fonts++] = current_font; } else --- dvipdfm/dvipdfm.1.orig Fri Jun 29 04:55:27 2001 +++ dvipdfm/dvipdfm.1 Sat Oct 6 02:32:25 2001 @@ -127,7 +127,8 @@ .TP 5 .B \-\^p " paper" Select the papersize by name (e.g., -.BR letter ", " legal ", " ledger ", " tabloid ", " a3 ", " a4 ", or " a5 +.BR letter ", " legal ", " ledger ", " tabloid ", " a3 ", " a4 ", " +.BR a5 ", " a6 ", " b3 ", " b4 ", " b5 ", " b6 ", or " b5var ) .TP 5 --- dvipdfm/dvipdfm.c.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/dvipdfm.c Sat Oct 6 02:32:25 2001 @@ -36,6 +36,7 @@ #include "pdfdev.h" #include "encodings.h" #include "type1.h" +#include "type0.h" #include "ttf.h" #include "colorsp.h" #include "pdfspecial.h" @@ -62,9 +63,15 @@ {"legal" , { 612.0, 1008.0}}, {"ledger" , { 1224.0, 792.0}}, {"tabloid" , { 792.0, 1224.0}}, + {"a6" , { 297.64, 420.91}}, {"a5" , { 420.91, 595.27}}, {"a4" , { 595.27, 841.82}}, - {"a3" , { 841.82, 1190.16}}}; + {"a3" , { 841.82, 1190.16}}, + {"b6" , { 364.25, 515.91}}, + {"b5" , { 515.91, 728.50}}, + {"b4" , { 728.50, 1031.81}}, + {"b3" , { 1031.81, 1457.00}}, + {"b5var" , { 515.91, 651.97}}}; static rect get_paper_size (char *string) { @@ -113,7 +120,8 @@ fprintf (stdout, "-l \t\tLandscape mode\n"); fprintf (stdout, "-m number\tSet additional magnification\n"); fprintf (stdout, "-p papersize\tSet papersize (letter, legal,\n"); - fprintf (stdout, " \tledger, tabloid, a4, or a3) [letter]\n"); + fprintf (stdout, " \tledger, tabloid, a6, a5, a4, a3,\n"); + fprintf (stdout, " \tb6, b5, b4, b3, or b5var) [a4]\n"); fprintf (stdout, "-r resolution\tSet resolution (in DPI) for raster fonts [600]\n"); fprintf (stdout, "-s pages\tSelect page ranges (-)\n"); fprintf (stdout, "-t \tEmbed thumbnail images\n"); @@ -129,7 +137,7 @@ exit(1); } -static double paper_width = 612.0, paper_height = 792.0; +static double paper_width = 595.27, paper_height = 841.82; static char landscape_mode = 0; static char ignore_colors = 0; static double mag = 1.0, x_offset=72.0, y_offset=72.0; @@ -402,6 +410,7 @@ #ifdef HAVE_TTF_FORMATS ttf_set_verbose(); #endif + type0_set_verbose(); break; case 'V': { --- dvipdfm/mpost.c.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/mpost.c Sat Oct 6 02:32:25 2001 @@ -1199,6 +1199,9 @@ } else if (**start == '(' && (obj = parse_pdf_string (start, end))) { PUSH (obj); + } else if (**start == '<' && + (obj = parse_pdf_hex_string (start, end))) { + PUSH (obj); } else if (**start == '/') { fprintf (stderr, "\nUnable to handle names in raw PS code."); dump (*start, end); @@ -1315,10 +1318,13 @@ p->c_urx, p->c_ury, res_name); if (!xobj) return NULL; + /* prevent dev_set_string() to be disturbed by wmode */ + dev_start_mp_mode(); /* Flesh out the contents */ if (!parse_contents (image_file)) { fprintf (stderr, "Errors occured while interpreting MetaPost file.\n\n"); } + dev_end_mp_mode(); /* Finish off the form */ end_form_xobj(); } else { --- dvipdfm/pdfdev.c.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/pdfdev.c Sat Oct 6 02:38:08 2001 @@ -21,7 +21,6 @@ mwicks@kettering.edu */ - #include "config.h" #include #include @@ -38,6 +37,7 @@ #include "pdfdoc.h" #include "pdfobj.h" #include "type1.h" +#include "type0.h" #include "ttf.h" #include "pkfont.h" #include "pdfspecial.h" @@ -65,7 +65,7 @@ /* Following dimensions in virtual device coordinates, which are points */ -static double page_width=612.0, page_height=792.0; +static double page_width=595.27, page_height=841.82; int page_size_readonly = 0; void dev_set_page_size (double width, double height) @@ -106,6 +106,23 @@ #define STRING_MODE 3 int motion_state = GRAPHICS_MODE; /* Start in graphics mode */ +/* + text_wmode (first bit: WMode(font), second bit: direction) + 00/11 normal - h(v) direction with h(v) version of a font + 01 -90 deg. rotated + 10 +90 deg. rotated +*/ +#define HH_MODE 0 +#define HV_MODE 1 +#define VH_MODE 2 +#define VV_MODE 3 +int text_wmode = HH_MODE; /* Start in horizontal-horizontal mode */ +int text_wmode_save = HH_MODE; /* for MetaPost mode */ +#define WMODE_CHANGES(p,q) ((abs(p-q) % 3) ? 1 : 0) +#define VERTFONT(p) (p & 0x02) +#define VERTDIR(p) (p & 0x01) +int force_reset = 0; +int mp_mode = 0; /* no HV and VH modes in MetaPost (PostScript) processing */ #define FORMAT_BUF_SIZE 4096 static char format_buffer[FORMAT_BUF_SIZE]; @@ -164,6 +181,7 @@ #define TYPE1 1 #define PK 2 #define TRUETYPE 3 +#define TYPE0 4 #define DEFAULT_MAP_FILE "fonts.map" @@ -177,6 +195,7 @@ char *used_chars; double extend, slant; int remap; + int wmode; /* WMode, horizontal: 0, vertical: 1 */ } *dev_font = NULL; static unsigned max_device_fonts = 0; @@ -360,6 +379,30 @@ return result; } +static void set_text_matrix(spt_t xpos, spt_t ypos, double slant, double extend) { + int len = 0; + + switch(text_wmode) { + case VH_MODE: + len += sprintf (format_buffer+len, " 0 %.7g -1 %.3g ", extend, slant); + break; + case HV_MODE: + len += sprintf (format_buffer+len, " 0 %.7g 1 %.3g ", -extend, -slant); + break; + default: /* normal mode */ + len += sprintf (format_buffer+len, " %.7g 0 %.3g 1 ", extend, slant); + } + len += centi_u_to_a (format_buffer+len, IDIVRND (xpos, CENTI_PDF_U)); + format_buffer[len++] = ' '; + len += centi_u_to_a (format_buffer+len, IDIVRND (ypos, CENTI_PDF_U)); + format_buffer[len++] = ' '; + format_buffer[len++] = 'T'; + format_buffer[len++] = 'm'; + + pdf_doc_add_to_page (format_buffer, len); + return; +} + /* * reset_text_state() outputs a BT * and does any necessary coordinate transformations @@ -368,28 +411,20 @@ static void reset_text_state(void) { - int len; text_xorigin = 0; text_yorigin = 0; text_offset = 0; /* * We need to reset the line matrix to handle slanted fonts */ - len = sprintf (format_buffer, " BT"); - if (current_font >= 0 && /* If not at top of page */ + pdf_doc_add_to_page (" BT", 3); + /* text_slant = 0 and text_extend = 1 at top of page */ + if (force_reset || (dev_font[current_font].slant != 0.0 || - dev_font[current_font].extend != 1.0)) { - len += sprintf (format_buffer+len, " %.7g 0 %.3g 1 ", - dev_font[current_font].extend, - dev_font[current_font].slant); - len += centi_u_to_a (format_buffer+len, IDIVRND (text_xorigin, CENTI_PDF_U)); - format_buffer[len++] = ' '; - len += centi_u_to_a (format_buffer+len, IDIVRND (text_yorigin, CENTI_PDF_U)); - format_buffer[len++] = ' '; - format_buffer[len++] = 'T'; - format_buffer[len++] = 'm'; - } - pdf_doc_add_to_page (format_buffer, len); + dev_font[current_font].extend != 1.0) || + (text_wmode != HH_MODE && text_wmode != VV_MODE)) + set_text_matrix(text_xorigin, text_yorigin, text_slant, text_extend); + force_reset = 0; } static void text_mode (void) @@ -417,6 +452,7 @@ pdf_doc_add_to_page (")]TJ", 4); case TEXT_MODE: pdf_doc_add_to_page (" ET", 3); + force_reset = 0; break; } motion_state = GRAPHICS_MODE; @@ -436,33 +472,65 @@ /* Following may be necessary after a rule (and also after specials) */ case TEXT_MODE: - delx = xpos - text_xorigin; - { - spt_t rounded_delx, desired_delx; - spt_t rounded_dely, desired_dely; - spt_t dvi_xerror, dvi_yerror; - - /* First round dely (it is needed for delx) */ - dely = ypos - text_yorigin; - desired_dely = dely; - rounded_dely = IDIVRND(desired_dely, CENTI_PDF_U) * CENTI_PDF_U; - /* Next round delx, precompensating for line transformation matrix */ - desired_delx = (delx-desired_dely*slant)/extend; - rounded_delx = IDIVRND(desired_delx, CENTI_PDF_U) * CENTI_PDF_U; - /* Estimate errors in DVI units */ - dvi_yerror = (desired_dely - rounded_dely); - dvi_xerror = (extend*(desired_delx - rounded_delx)+slant*dvi_yerror); - format_buffer[len++] = ' '; - len += centi_u_to_a (format_buffer+len, rounded_delx/CENTI_PDF_U); - format_buffer[len++] = ' '; - len += centi_u_to_a (format_buffer+len, rounded_dely/CENTI_PDF_U); - pdf_doc_add_to_page (format_buffer, len); - len = 0; - pdf_doc_add_to_page (" TD[(", 5); - text_xorigin = xpos-dvi_xerror; - text_yorigin = ypos-dvi_yerror; + if (force_reset) { + text_xorigin = xpos; + text_yorigin = ypos; + set_text_matrix(xpos, ypos, slant, extend); + pdf_doc_add_to_page ("[(", 2); + force_reset = 0; + } else { + delx = xpos - text_xorigin; + { + spt_t rounded_delx, desired_delx; + spt_t rounded_dely, desired_dely; + spt_t dvi_xerror, dvi_yerror; + + /* First round dely (it is needed for delx) */ + dely = ypos - text_yorigin; + format_buffer[len++] = ' '; + switch(text_wmode) { /* precompensating for line transformation matrix */ + case HV_MODE: + desired_delx = delx; + rounded_delx = IDIVRND(desired_delx, CENTI_PDF_U) * CENTI_PDF_U; + /* Next round dely */ + desired_dely = (dely+desired_delx*slant)/extend; + rounded_dely = IDIVRND(desired_dely, CENTI_PDF_U) * CENTI_PDF_U; + len += centi_u_to_a (format_buffer+len, -rounded_dely/CENTI_PDF_U); + format_buffer[len++] = ' '; + len += centi_u_to_a (format_buffer+len, rounded_delx/CENTI_PDF_U); + break; + case VH_MODE: + desired_delx = delx; + rounded_delx = IDIVRND(desired_delx, CENTI_PDF_U) * CENTI_PDF_U; + /* Next round dely */ + desired_dely = (dely+desired_delx*slant)/extend; /* slant = 0 */ + rounded_dely = IDIVRND(desired_dely, CENTI_PDF_U) * CENTI_PDF_U; + len += centi_u_to_a (format_buffer+len, rounded_dely/CENTI_PDF_U); + format_buffer[len++] = ' '; + len += centi_u_to_a (format_buffer+len, -rounded_delx/CENTI_PDF_U); + break; + default: /* HH and VV */ + desired_dely = dely; + rounded_dely = IDIVRND(desired_dely, CENTI_PDF_U) * CENTI_PDF_U; + /* Next round delx, precompensating for line transformation matrix */ + desired_delx = (delx-desired_dely*slant)/extend; + rounded_delx = IDIVRND(desired_delx, CENTI_PDF_U) * CENTI_PDF_U; + len += centi_u_to_a (format_buffer+len, rounded_delx/CENTI_PDF_U); + format_buffer[len++] = ' '; + len += centi_u_to_a (format_buffer+len, rounded_dely/CENTI_PDF_U); + break; + } + pdf_doc_add_to_page (format_buffer, len); + len = 0; + pdf_doc_add_to_page (" TD[(", 5); + /* Estimate errors in DVI units */ + dvi_yerror = (desired_dely - rounded_dely); + dvi_xerror = (extend*(desired_delx - rounded_delx)+slant*dvi_yerror); + text_xorigin = xpos-dvi_xerror; + text_yorigin = ypos-dvi_yerror; + } + text_offset = 0; } - text_offset = 0; break; } motion_state = STRING_MODE; @@ -482,26 +550,32 @@ static void dev_set_font (int font_id) { int len = 0; + int prev_wmode = text_wmode; text_mode(); + if (dev_font[font_id].wmode == 0) { + if (mp_mode) { + text_wmode = HH_MODE; + } else { + text_wmode &= 1; + } + } else if (dev_font[font_id].wmode == 1) { + if (mp_mode) { + text_wmode = VV_MODE; + } else { + text_wmode |= 2; + } + } len = sprintf (format_buffer, "/%s ", dev_font[font_id].short_name); len += centi_u_to_a (format_buffer+len, IDIVRND(dev_font[font_id].sptsize, CENTI_PDF_U)); format_buffer[len++] = ' '; format_buffer[len++] = 'T'; format_buffer[len++] = 'f'; if (dev_font[font_id].slant != text_slant || - dev_font[font_id].extend != text_extend) { - len += sprintf (format_buffer+len, " %.7g 0 %.3g 1 ", - dev_font[font_id].extend, - dev_font[font_id].slant); - len += centi_u_to_a (format_buffer+len, IDIVRND(text_xorigin, CENTI_PDF_U)); - format_buffer[len++] = ' '; - len += centi_u_to_a (format_buffer+len, IDIVRND(text_yorigin, CENTI_PDF_U)); - format_buffer[len++] = ' '; - format_buffer[len++] = 'T'; - format_buffer[len++] = 'm'; - /* There's no longer any uncertainty about where we are */ + dev_font[font_id].extend != text_extend || + WMODE_CHANGES(prev_wmode, text_wmode)) { text_slant = dev_font[font_id].slant; text_extend = dev_font[font_id].extend; + force_reset = 1; } pdf_doc_add_to_page (format_buffer, len); /* Add to Font list in Resource dictionary for this page */ @@ -519,23 +593,39 @@ { int len = 0; long kern; + int ctype = 1; if (font_id != current_font) dev_set_font(font_id); /* Force a Tf since we are actually trying to write a character */ + /* double-byte char or single-byte char */ + ctype = (dev_font[font_id].format == TYPE0) ? 2 : 1; /* Kern is in units of character units, i.e., 1000 = 1 em. */ /* The following formula is of the form a*x/b where a, x, and b are long integers. Since in integer arithmetic (a*x) could overflow and a*(x/b) would not be accurate, we use floating point arithmetic rather than trying to do this all with integer arithmetic. */ - kern = - (1000.0/dev_font[font_id].extend*(text_xorigin+text_offset-xpos))/dev_font[font_id].sptsize; - - if (labs(ypos-text_yorigin) > CENTI_PDF_U || /* CENTI_PDF_U is smallest resolvable dimension */ - abs(kern) > 32000) { /* Some PDF Readers fail on large kerns */ - text_mode(); - kern = 0; + if (! VERTDIR(text_wmode)) { + kern = + (1000.0/dev_font[font_id].extend*(text_xorigin+text_offset-xpos))/dev_font[font_id].sptsize; + if (force_reset || /* reset text state */ + labs(ypos-text_yorigin) > CENTI_PDF_U || /* CENTI_PDF_U is smallest resolvable dimension */ + abs(kern) > 32000 /* Some PDF Readers fail on large kerns */ + ) { + text_mode(); + kern = 0; + } + } else { + kern = + (1000.0/dev_font[font_id].extend*(ypos-text_yorigin+text_offset))/dev_font[font_id].sptsize; + if (force_reset || /* reset text state */ + labs(xpos-text_xorigin) > CENTI_PDF_U || /* CENTI_PDF_U is smallest resolvable dimension */ + abs(kern) > 32000 /* Some PDF Readers fail on large kerns */ + ) { + text_mode(); + kern = 0; + } } if (motion_state != STRING_MODE) string_mode(xpos, ypos, dev_font[font_id].slant, dev_font[font_id].extend); @@ -546,7 +636,11 @@ /* This routine needs to be fast, so we don't call sprintf() or strcpy() */ format_buffer[len++] = ')'; - len += inttoa (format_buffer+len, kern); + if (VERTFONT(text_wmode)) { /* PDF vertical writing mode for CJK characters */ + len += inttoa (format_buffer+len, -kern); + } else { + len += inttoa (format_buffer+len, kern); + } format_buffer[len++] = '('; pdf_doc_add_to_page (format_buffer, len); len = 0; @@ -559,7 +653,7 @@ /* Record characters used for partial font embedding */ /* Fonts without pfbs don't get counted and have used_chars set to null */ - if (dev_font[font_id].used_chars != NULL) { + if ((dev_font[font_id].used_chars != NULL) && ctype == 1) { int i; if (dev_font[font_id].remap) for (i=0; i=0) { font_format = TRUETYPE; #endif /* HAVE_TTF_FORMATS */ + } else if ((font_id = type0_font (font_name, tfm_id, + short_name, encoding_id, remap))>=0) { + font_format = TYPE0; } else if ((font_id = pk_font (font_name, ptsize*dvi2pts, tfm_id, short_name))>=0) { @@ -1094,7 +1193,13 @@ strcpy (dev_font[this_font].tex_name, tex_name); dev_font[this_font].sptsize = ptsize; dev_font[this_font].format = font_format; - dev_font[this_font].slant = slant; + dev_font[this_font].wmode = is_vertical(tfm_id); + if (dev_font[this_font].wmode && slant != 0.0) { + fprintf(stderr, "Warning: slant option ignored (vertical font)\n"); + dev_font[this_font].slant = 0.0; + } else { + dev_font[this_font].slant = slant; + } dev_font[this_font].extend = extend; dev_font[this_font].remap = remap; dev_font[this_font].used_on_this_page = 0; @@ -1111,6 +1216,11 @@ dev_font[this_font].used_chars = ttf_font_used(font_id); break; #endif /* HAVE_TTF_FORMATS */ + case TYPE0: + dev_font[this_font].font_resource = + type0_font_resource(font_id); + dev_font[this_font].used_chars = type0_font_used(font_id); + break; case PK: dev_font[this_font].font_resource = pk_font_resource (font_id); dev_font[this_font].used_chars = pk_font_used(font_id); @@ -1141,6 +1251,7 @@ that there will be an attempt to add the resource to the page resource dict. However, the second attempt will do nothing */ dev_font[this_font].used_on_this_page = 0; + dev_font[this_font].wmode = dev_font[i].wmode; dev_font[this_font].font_resource = pdf_link_obj(dev_font[i].font_resource); /* These two fonts are treated as having the same physical "used_chars" */ @@ -1170,6 +1281,7 @@ RELEASE (font_map); /* Close the various font handlers */ type1_close_all(); + type0_close_all(); pk_close_all(); #ifdef HAVE_TTF_FORMATS ttf_close_all(); @@ -1316,21 +1428,44 @@ phys_width = scale*width; phys_height = scale*height; phys_depth = scale*depth; - pdf_doc_expand_box (dev_phys_x(), dev_phys_y()-phys_depth, - dev_phys_x()+phys_width, - dev_phys_y()+phys_height); + if (! VERTDIR(text_wmode)) { + pdf_doc_expand_box (dev_phys_x(), dev_phys_y()-phys_depth, + dev_phys_x()+phys_width, + dev_phys_y()+phys_height); + } else { + pdf_doc_expand_box (dev_phys_x()-phys_depth, dev_phys_y()-phys_width, + dev_phys_x()+phys_height, + dev_phys_y()); + } } } +int dev_wmode (void) +{ + return VERTDIR(text_wmode); +} +void dev_set_wmode (int dir) +{ + int prev_wmode = text_wmode; + if (dir) { + text_wmode |= 1; + } else { + text_wmode &= 2; + } + if (WMODE_CHANGES(prev_wmode, text_wmode)) force_reset = 1; +} +void dev_start_mp_mode (void) /* MetaPost mode (or PostScript mode) */ +{ + text_wmode_save = text_wmode; + text_wmode = HH_MODE; + mp_mode = 1; +} - - - - - - - - +void dev_end_mp_mode (void) +{ + text_wmode = text_wmode_save; + mp_mode = 0; +} --- dvipdfm/pdfdev.h.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/pdfdev.h Sat Oct 6 02:32:25 2001 @@ -83,6 +83,10 @@ extern void dev_untag_depth (void); extern void dev_expand_box (spt_t width, spt_t height, spt_t depth); extern void dev_link_annot (unsigned char flag); +extern int dev_wmode (void); +extern void dev_set_wmode (int wmode); +extern void dev_start_mp_mode (void); +extern void dev_end_mp_mode (void); #endif /* PDFDEV_H */ --- dvipdfm/pdfspecial.c.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/pdfspecial.c Sat Oct 6 02:32:25 2001 @@ -1023,8 +1023,13 @@ pdf_doc_add_to_page_xobjects (res_name, pdf_ref_obj(result)); pdf_doc_add_to_page (" q", 2); /* Handle the conversion to PDF stream units here */ - add_xform_matrix (x_user, y_user, - p->xscale/pdf_dev_scale(), p->yscale/pdf_dev_scale(), p->rotate); + if (dev_wmode() == 1) { /* rotated 90 deg. in vertical writing mode */ + add_xform_matrix (x_user, y_user, + p->xscale/pdf_dev_scale(), p->yscale/pdf_dev_scale(), p->rotate - 0.50 * M_PI); + } else { + add_xform_matrix (x_user, y_user, + p->xscale/pdf_dev_scale(), p->yscale/pdf_dev_scale(), p->rotate); + } if (p->depth != 0.0) add_xform_matrix (0.0, -p->depth, 1.0, 1.0, 0.0); sprintf (work_buffer, " /%s Do Q", res_name); --- dvipdfm/pdfparse.h.orig Fri Jun 29 04:55:26 2001 +++ dvipdfm/pdfparse.h Sat Oct 6 02:32:25 2001 @@ -66,6 +66,7 @@ extern char *parse_c_string (char **start, char*end); extern pdf_obj *parse_pdf_string (char **start, char*end); +extern pdf_obj *parse_pdf_hex_string (char **start, char*end); extern pdf_obj *parse_pdf_name (char **start, char*end); extern pdf_obj *parse_pdf_array (char **start, char*end); extern pdf_obj *parse_pdf_object (char **start, char*end); --- dvipdfm/tfm.c.orig Fri Jun 29 04:55:27 2001 +++ dvipdfm/tfm.c Sat Oct 6 02:32:25 2001 @@ -33,6 +33,8 @@ #include "config.h" #define FWBASE ((double) (1<<20)) +#define JFM_ID 11 +#define JFMV_ID 9 /* vertical version of JFM */ static char tfm_verbose = 0; static char tfm_debug = 0; @@ -42,6 +44,8 @@ struct a_tfm { + UNSIGNED_BYTE id; /* id = 11(9) for jfm(vertical) */ + UNSIGNED_BYTE nt; /* number of charcter types for jfm */ UNSIGNED_QUAD wlenfile, wlenheader; UNSIGNED_QUAD bc, ec; UNSIGNED_QUAD nwidths, nheights, ndepths; @@ -59,6 +63,7 @@ SIGNED_QUAD *height; SIGNED_QUAD *depth; char *tex_name; + UNSIGNED_PAIR *chartypes; fixword *unpacked_widths; fixword *unpacked_heights; fixword *unpacked_depths; @@ -66,6 +71,8 @@ void a_tfm_init (struct a_tfm *a_tfm) { + a_tfm->id = 0; + a_tfm->nt = 0; a_tfm->header = NULL; a_tfm->char_info = NULL; a_tfm->width_index = NULL; @@ -74,6 +81,7 @@ a_tfm->width = NULL; a_tfm->height = NULL; a_tfm->depth = NULL; + a_tfm->chartypes = NULL; a_tfm->unpacked_widths = NULL; a_tfm->unpacked_heights = NULL; a_tfm->unpacked_depths = NULL; @@ -117,6 +125,9 @@ result += a_tfm -> nkern; result += a_tfm -> nextens; result += a_tfm -> nfonparm; + if (a_tfm->id == JFM_ID || a_tfm->id == JFMV_ID) { + result += a_tfm -> nt + 1; + } return result; } @@ -140,7 +151,17 @@ static void get_sizes (FILE *tfm_file, SIGNED_QUAD tfm_file_size, struct a_tfm *a_tfm) { - a_tfm -> wlenfile = get_unsigned_pair (tfm_file); + UNSIGNED_PAIR tfm_id; + + tfm_id = get_unsigned_pair (tfm_file); + if (tfm_id == JFM_ID || tfm_id == JFMV_ID) { /* is jfm */ + a_tfm -> id = tfm_id; + a_tfm -> nt = get_unsigned_pair (tfm_file); + a_tfm -> wlenfile = get_unsigned_pair (tfm_file); + if (tfm_debug) fprintf (stderr, "size: %ld\n", a_tfm->wlenfile); + } else { + a_tfm -> wlenfile = tfm_id; + } a_tfm -> wlenheader = get_unsigned_pair (tfm_file); a_tfm -> bc = get_unsigned_pair (tfm_file); a_tfm -> ec = get_unsigned_pair (tfm_file); @@ -274,6 +295,23 @@ *a = NULL; return; } + +static void do_char_type_array(FILE *tfm_file, struct a_tfm *a_tfm) +{ + int i; + UNSIGNED_PAIR charcode; + UNSIGNED_PAIR chartype; + a_tfm -> chartypes = NEW (65536, UNSIGNED_PAIR); + for (i=0; i<65536; i++) { + (a_tfm->chartypes)[i] = 0; + } + for (i=0; i < a_tfm->nt; i++ ) { + charcode = get_unsigned_pair(tfm_file); + chartype = get_unsigned_pair(tfm_file); + (a_tfm->chartypes)[charcode] = chartype; + } +} + static void unpack_widths(struct a_tfm *a_tfm) { int i; @@ -330,6 +368,9 @@ if (tfm_debug) fprintf (stderr, "Reading %ld word header\n", a_tfm->wlenheader); do_fix_word_array (tfm_file, &(a_tfm -> header), a_tfm -> wlenheader); + if (a_tfm->id == JFM_ID || a_tfm->id == JFMV_ID) { + do_char_type_array (tfm_file, a_tfm); + } if (tfm_debug) fprintf (stderr, "Reading %ld char_infos\n", (a_tfm->ec)-(a_tfm->bc)+1); do_unsigned_quad_array (tfm_file, &(a_tfm -> char_info), (a_tfm->ec)-(a_tfm->bc)+1); @@ -564,6 +605,8 @@ RELEASE (tfm[i].unpacked_widths); RELEASE (tfm[i].unpacked_heights); RELEASE (tfm[i].unpacked_depths); + if (tfm[i].chartypes) + RELEASE (tfm[i].chartypes); if (tfm[i].width_index) RELEASE (tfm[i].width_index); if (tfm[i].height_index) @@ -579,6 +622,8 @@ as a (double) fraction of the design size */ double tfm_get_width (int font_id, UNSIGNED_QUAD ch) { + if (tfm[font_id].id == JFM_ID || tfm[font_id].id == JFMV_ID ) + ch = (tfm[font_id].chartypes)[ch]; if (tfm[font_id].unpacked_widths && ch <= tfm[font_id].ec) return (double) (tfm[font_id].unpacked_widths)[ch] / FWBASE; else return 0.0; @@ -586,6 +631,8 @@ double tfm_get_height (int font_id, UNSIGNED_QUAD ch) { + if (tfm[font_id].id == JFM_ID || tfm[font_id].id == JFMV_ID ) + ch = (tfm[font_id].chartypes)[ch]; if (tfm[font_id].unpacked_heights && ch <= tfm[font_id].ec) return (double) (tfm[font_id].unpacked_heights)[ch] / FWBASE; else return 0.0; @@ -593,6 +640,8 @@ double tfm_get_depth (int font_id, UNSIGNED_QUAD ch) { + if (tfm[font_id].id == JFM_ID || tfm[font_id].id == JFMV_ID ) + ch = (tfm[font_id].chartypes)[ch]; if (tfm[font_id].unpacked_depths && ch <= tfm[font_id].ec) return (tfm[font_id].unpacked_depths)[ch]/FWBASE; else return 0.0; @@ -600,6 +649,8 @@ fixword tfm_get_fw_width (int font_id, UNSIGNED_QUAD ch) { + if (tfm[font_id].id == JFM_ID || tfm[font_id].id == JFMV_ID ) + ch = (tfm[font_id].chartypes)[ch]; if (tfm[font_id].unpacked_widths && ch <= tfm[font_id].ec) { return (tfm[font_id].unpacked_widths)[ch]; } @@ -608,6 +659,8 @@ fixword tfm_get_fw_height (int font_id, UNSIGNED_QUAD ch) { + if (tfm[font_id].id == JFM_ID || tfm[font_id].id == JFMV_ID ) + ch = (tfm[font_id].chartypes)[ch]; if (tfm[font_id].unpacked_heights && ch <= tfm[font_id].ec) return (tfm[font_id].unpacked_heights)[ch]; return 0; @@ -615,6 +668,8 @@ fixword tfm_get_fw_depth (int font_id, UNSIGNED_QUAD ch) { + if (tfm[font_id].id == JFM_ID || tfm[font_id].id == JFMV_ID ) + ch = (tfm[font_id].chartypes)[ch]; if (tfm[font_id].unpacked_depths && ch <= tfm[font_id].ec) return (tfm[font_id].unpacked_depths)[ch]; return 0; @@ -711,4 +766,14 @@ max = (tfm[font_id].depth)[i]; } return (max/FWBASE); +} + +char is_jfm (int font_id) +{ + return (tfm[font_id].id == JFM_ID || tfm[font_id].id == JFMV_ID) ? 1 : 0; +} + +char is_vertical (int font_id) /* Vertical version of JFM */ +{ + return (tfm[font_id].id == JFMV_ID) ? 1 : 0; } --- dvipdfm/tfm.h.orig Fri Jun 29 04:55:27 2001 +++ dvipdfm/tfm.h Sat Oct 6 02:32:25 2001 @@ -59,5 +59,6 @@ extern double tfm_get_max_width (int font_id); extern int tfm_is_fixed_width (int font_id); extern double tfm_get_max_depth (int font_id); - +extern char is_jfm (int font_id); +extern char is_vertical (int font_id); #endif /* TFM_H */ --- dvipdfm/type0.c.orig Sat Oct 6 02:38:30 2001 +++ dvipdfm/type0.c Sat Oct 6 02:32:25 2001 @@ -0,0 +1,198 @@ +/* + Type0 Font (aka Composite Font) + + from PDF Reference 2nd. ed., p 311 + PDF 1.2 introduces a general architecture for composite fonts that + theoretically allows a Type 0 font to have multiple descendants, which + might themselves be Type 0 fonts. However, in versions up to and + including PDF 1.3, only a single descendant is allowed, which must be + a CIDFont (not a font). This restriction may be relaxed in a future + PDF version. + + Shunsaku Hirata +*/ +#include "config.h" +#include +#include +#include "mem.h" +#include "error.h" +#include "pdfobj.h" +#include "numbers.h" +#include "tfm.h" +#include "pdflimits.h" +#include "cid.h" +#include "type0.h" + +static unsigned char verbose = 0; + +void type0_set_verbose(void) +{ + cid_set_verbose(); + if (verbose < 255) { + verbose += 1; + } +} + +int num_type0_fonts = 0, max_type0_fonts; + +/* Composite fonts are not supported */ +struct a_type0_font +{ + pdf_obj *indirect; + char *encoding; + char *used_chars; + int cid_id; /* wrong, but still only single descendant is allowed */ + int wmode; /* writing mode, horizontal: 0, vertical: 1 */ +} *type0_fonts = NULL; + +static void init_a_type0_font (struct a_type0_font *this_type0_font) +{ + this_type0_font->indirect = NULL; + this_type0_font->encoding = NULL; + this_type0_font->used_chars = NULL; + this_type0_font->cid_id = -1; + this_type0_font->wmode = 0; +} + +pdf_obj *type0_font_resource (int type0_id) +{ + if (type0_id>=0 && type0_id=0 && type0_id=0 && type0_id= 0) { + /* ERROR("unexpected encoding id. encording field shoud be `default' or `none'."); */ + return result; + } else { /* only JIS encoding is supported */ + encoding = NEW(2, char); + if ((wmode = is_vertical(tfm_font_id)) == 1) { + sprintf(encoding, "V"); + } else { + sprintf(encoding, "H"); + } + } + + if (map_name && (result = cid_find_parent(map_name, encoding)) >= 0) { + } else if (map_name && ((cid_id = cid_get_id(map_name)) >= 0)) { + /* + BaseFont name may contain encoding name, + while CID-keyed fonts do not contain any encodings. + */ + if (num_type0_fonts >= max_type0_fonts) { + max_type0_fonts = MAX (max_type0_fonts+MAX_FONTS, num_type0_fonts+1); + type0_fonts = RENEW (type0_fonts, max_type0_fonts, struct a_type0_font); + } + + init_a_type0_font (type0_fonts+num_type0_fonts); + type0_fonts[num_type0_fonts].cid_id = cid_id; + + font_resource = pdf_new_dict (); + pdf_add_dict (font_resource, + pdf_new_name ("Type"), + pdf_new_name ("Font")); + pdf_add_dict (font_resource, + pdf_new_name ("Subtype"), + pdf_new_name ("Type0")); + /* + Name: + Name used in font resource dictionary - required only in PDF-1.0 + Note: This entry is obsolescent and its use is no longer recommended. + (See implementation note 39 in Appendix H., PDF Reference v1.3, 2nd ed.) + */ + pdf_add_dict (font_resource, + pdf_new_name ("Name"), + pdf_new_name (resource_name)); + /* No FontDescritor, instead DescendantFonts appears here */ + tmp1 = pdf_new_array (); + pdf_add_array(tmp1, cid_call_descendant(num_type0_fonts, cid_id)); + pdf_add_dict (font_resource, pdf_new_name ("DescendantFonts"), tmp1); + /* Future PDF spec. will allow DesecendantFonts to refer multiple fonts */ + /* PostScript Font name */ + fontname = cid_fontname(cid_id); + if (verbose) fprintf(stderr, "(%s:%s)", "CID", fontname); + len = strlen(fontname)+strlen(encoding)+2; /* don't forget `-' */ + fullname = NEW (len, char); + snprintf(fullname, len, "%s-%s", fontname, encoding); + pdf_add_dict (font_resource, + pdf_new_name ("BaseFont"), + pdf_new_name (fullname)); + RELEASE(fullname); + pdf_add_dict (font_resource, + pdf_new_name ("Encoding"), + pdf_new_name(encoding)); + + type0_fonts[num_type0_fonts].indirect = pdf_ref_obj(font_resource); + type0_fonts[num_type0_fonts].encoding = NEW(strlen(encoding)+1, char); + strcpy(type0_fonts[num_type0_fonts].encoding, encoding) ; + type0_fonts[num_type0_fonts].wmode = wmode; + pdf_release_obj (font_resource); + result = num_type0_fonts; + num_type0_fonts += 1; + } else { /* not a CID font */ + result = -1; + } + + RELEASE(encoding); + +#ifdef MEM_DEBUG + MEM_END +#endif /* MEM_DEBUG */ + return result; +} + +void type0_close_all (void) +{ + int i; + + cid_flush_all(); + for (i=0; i