[gs-cvs] gs/src

Igor Melichev igor at casper.ghostscript.com
Wed Jul 24 00:45:31 PDT 2002


Update of /cvs/ghostscript/gs/src
In directory casper:/tmp/cvs-serv27053/gs/src

Modified Files:
	gdevpdte.c gdevpdtf.c gdevpdtt.c zchar1.c gdevpdtf.h 
	gdevpdtt.h gxfont.h 
Log Message:
pdfwrite: implementing WMode 1 for simple fonts.


Index: gdevpdte.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevpdte.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- gdevpdte.c	9 Jul 2002 14:29:35 -0000	1.7
+++ gdevpdte.c	24 Jul 2002 07:45:28 -0000	1.8
@@ -314,9 +314,15 @@
 	    pdfont->Widths[ch] = pwidths->Width.w;
 	    pdfont->real_widths[ch] = pwidths->real_width.w;
 	}
+	if (pdfont->u.simple.v != 0)
+	    pdfont->u.simple.v[ch] = pwidths->v;
     } else {
 	pwidths->Width.w = pdfont->Widths[ch];
 	pwidths->real_width.w = pdfont->real_widths[ch];
+	if (pdfont->u.simple.v != 0)
+	    pwidths->v = pdfont->u.simple.v[ch];
+	else
+	    pwidths->v.x = pwidths->v.y = 0;
 	if (font->WMode) {
 	    pwidths->Width.xy.x = 0;
 	    pwidths->Width.xy.y = pwidths->Width.w;
@@ -393,6 +399,35 @@
 
     return widths_differ;
 }
+
+/*
+ * Retrieve glyph origing shift for WMode = 1 in design units.
+ */
+private void 
+pdf_glyph_origin(pdf_font_resource_t *pdfont, int ch, int WMode, gs_point *p)
+{
+    if (WMode == 0) {
+        p->x = p->y = 0;
+	return;
+    }
+    /* For CID fonts PDF viewers provide glyph origin shift automatically.
+     * Therefore we only need to do for non-CID fonts.
+     */
+    switch (pdfont->FontType) {
+	case ft_encrypted:
+	case ft_encrypted2:
+	case ft_TrueType:
+	    if (pdfont->u.simple.v != 0)
+		*p = pdfont->u.simple.v[ch];
+	    else
+		p->x = p->y = 0;
+	    break;
+	default:
+	    p->x = p->y = 0;
+	    break;
+    }
+}
+
 /*
  * Emulate TEXT_ADD_TO_ALL_WIDTHS and/or TEXT_ADD_TO_SPACE_WIDTH,
  * and implement TEXT_REPLACE_WIDTHS if requested.
@@ -427,9 +462,25 @@
 	int code = pdf_char_widths(ppts->values.pdfont, pstr->data[i], font,
 				   &cw);
 	gs_point did, wanted;	/* user space */
+	gs_point v; /* design space */
 
+	pdf_glyph_origin(ppts->values.pdfont, pstr->data[i], font->WMode, &v);
 	if (code < 0)
 	    break;
+
+	if (v.x != 0 || v.y != 0) {
+	    gs_point glyph_origin_shift;
+
+	    gs_distance_transform(-v.x * scale, -v.y * scale,
+				  &ctm_only(pte->pis), &glyph_origin_shift);
+	    if (glyph_origin_shift.x != 0 || glyph_origin_shift.y != 0) {
+		ppts->values.matrix.tx = start.x + total.x + glyph_origin_shift.x;
+		ppts->values.matrix.ty = start.y + total.y + glyph_origin_shift.y;
+		code = pdf_set_text_state_values(pdev, &ppts->values);
+		if (code < 0)
+		    break;
+	    }
+	}
 	if (pte->text.operation & TEXT_DO_DRAW) {
 	    gs_distance_transform(cw.Width.xy.x * scale,
 				  cw.Width.xy.y * scale,

Index: gdevpdtf.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevpdtf.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- gdevpdtf.c	9 Jul 2002 14:29:35 -0000	1.9
+++ gdevpdtf.c	24 Jul 2002 07:45:28 -0000	1.10
@@ -70,7 +70,7 @@
  case ft_user_defined:
      ENUM_RETURN(pdfont->u.simple.s.type3.char_procs);
  default:
-     ENUM_RETURN(0);
+     ENUM_RETURN(pdfont->u.simple.v);
 }
 ENUM_PTRS_END
 private
@@ -99,6 +99,7 @@
 	break;
     default:
 	RELOC_VAR(pdfont->u.simple.Encoding);
+	RELOC_VAR(pdfont->u.simple.v);
 	/* falls through */
     case ft_user_defined:
 	RELOC_VAR(pdfont->u.simple.s.type3.char_procs);
@@ -660,13 +661,28 @@
 		      gs_id rid, pdf_font_descriptor_t *pfd)
 {
     pdf_font_resource_t *pdfont;
-    int code = font_resource_encoded_alloc(pdev, &pdfont, rid,
+    gs_font_base *pfont = pdf_font_descriptor_font(pfd);
+    gs_point *v;
+    int code;
+
+    if (pfont->WMode) {
+	v = (gs_point *)gs_alloc_byte_array(pdev->pdf_memory, 
+			256, sizeof(gs_point), "pdf_font_simple_alloc");
+	if (v == 0)
+	    return_error(gs_error_VMerror);
+	memset(v, 0, 256 * sizeof(*v));
+    }
+    code = font_resource_encoded_alloc(pdev, &pdfont, rid,
 					   pdf_font_descriptor_FontType(pfd),
 					   pdf_write_contents_simple);
 
-    if (code < 0)
+    if (code < 0) {
+	gs_free_object(pdev->pdf_memory, v,
+		       "pdf_font_simple_alloc");
 	return code;
+    }
     pdfont->FontDescriptor = pfd;
+    pdfont->u.simple.v = v;
     set_is_MM_instance(pdfont, pdf_font_descriptor_font(pfd));
     *ppfres = pdfont;
     return pdf_compute_BaseFont(pdev, pdfont);

Index: gdevpdtt.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevpdtt.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- gdevpdtt.c	9 Jul 2002 14:29:35 -0000	1.6
+++ gdevpdtt.c	24 Jul 2002 07:45:28 -0000	1.7
@@ -673,6 +673,7 @@
     double scale = font_orig_scale((const gs_font *)pdf_font_resource_font(pdfont)) * 1000.0;
     int code, rcode = 0;
 
+    pwidths->v.x = pwidths->v.y = 0;
     if (glyph != GS_NO_GLYPH &&
 	(code = font->procs.glyph_info((gs_font *)font, glyph, NULL,
 				       (GLYPH_INFO_WIDTH0 << wmode) |
@@ -698,6 +699,7 @@
 		)
 		return code;
 	    rcode |= code;
+	    pwidths->v = info.v;
 	} else
 	    pwidths->real_width = pwidths->Width;
 	/*

Index: zchar1.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/zchar1.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- zchar1.c	16 Jul 2002 16:47:39 -0000	1.20
+++ zchar1.c	24 Jul 2002 07:45:28 -0000	1.21
@@ -1050,6 +1050,8 @@
 	    modified_widths = true;
 	    info->width[1].x = wv[0];
 	    info->width[1].y = wv[1];
+	    info->v.x = wv[2];
+	    info->v.y = wv[3];
 	    done_members = width_members;
 	    width_members = 0;
 	}
@@ -1061,6 +1063,8 @@
 	    modified_widths = true;
 	    info->width[wmode].x = sbw[2];
 	    info->width[wmode].y = sbw[3];
+	    info->v.x = 0;
+	    info->v.y = 0;
 	    done_members = width_members;
 	    width_members = 0;
 	}

Index: gdevpdtf.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevpdtf.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- gdevpdtf.h	28 Jun 2002 01:48:41 -0000	1.3
+++ gdevpdtf.h	24 Jul 2002 07:45:28 -0000	1.4
@@ -203,6 +203,7 @@
 	     */
 	    gs_encoding_index_t BaseEncoding;
 	    pdf_encoding_element_t *Encoding; /* [256], not for Type 3 */
+	    gs_point *v; /* [256], glyph origin for WMode 1 */
 
 	    union {
 

Index: gdevpdtt.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/gdevpdtt.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- gdevpdtt.h	9 Jul 2002 14:29:35 -0000	1.4
+++ gdevpdtt.h	24 Jul 2002 07:45:28 -0000	1.5
@@ -120,6 +120,7 @@
 typedef struct pdf_glyph_widths_s {
     pdf_glyph_width_t Width;		/* unmodified, for Widths */
     pdf_glyph_width_t real_width;	/* possibly modified, for rendering */
+    gs_point v;				/* glyph origin for WMode 1 */
 } pdf_glyph_widths_t;
 
 /* ---------------- Procedures ---------------- */

Index: gxfont.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/gxfont.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- gxfont.h	16 Jun 2002 08:45:43 -0000	1.14
+++ gxfont.h	24 Jul 2002 07:45:28 -0000	1.15
@@ -141,6 +141,7 @@
 #define GLYPH_INFO_WIDTH1 2	/* must be WIDTH0 << 1 */
 #define GLYPH_INFO_WIDTHS (GLYPH_INFO_WIDTH0 | GLYPH_INFO_WIDTH1)
     gs_point width[2];		/* width for WMode 0/1 */
+    gs_point v;			/* glyph origin for WMode 1 */
 #define GLYPH_INFO_BBOX 4
     gs_rect bbox;
 #define GLYPH_INFO_NUM_PIECES 8




More information about the gs-cvs mailing list