[gs-cvs] rev 9335 - trunk/gs/base

leonardo at ghostscript.com leonardo at ghostscript.com
Thu Jan 8 04:43:28 PST 2009


Author: leonardo
Date: 2009-01-08 04:43:28 -0800 (Thu, 08 Jan 2009)
New Revision: 9335

Modified:
   trunk/gs/base/gstype42.c
Log:
Fix (TT font handler) : Wrong glyph posiitions with vertical writing mode (continued).

DETAILS :

Bug 689304 "improper handling of vertical japanese text".

This is fourth partial patch for the bug 689304.
It adds a code for processing CoverageFormat2,
which is used by IPAfont00203.

Besides that, in the old CoverageFormat1 code
subst.GlyphCount was used instead cov.GlyphCount . 
It didn't cause a problem because (we guess)
normally they are equal.

The field CoverageFormat2::RangeRecord is renamed into 
RangeArray to avoid possible conflict with same name for
a structure type. Rather it is a correct C,
we're not sure that all compilers accept it with no warning.

EXPECTED DIFFERENCES :

None.


Modified: trunk/gs/base/gstype42.c
===================================================================
--- trunk/gs/base/gstype42.c	2009-01-08 09:17:18 UTC (rev 9334)
+++ trunk/gs/base/gstype42.c	2009-01-08 12:43:28 UTC (rev 9335)
@@ -736,7 +736,7 @@
     typedef struct CoverageFormat2_s {
 	uint16_t CoverageFormat; /* ==2 */
 	uint16_t RangeCount;
-	GlyphID RangeRecord[1/*RangeCount*/]; /* Array of GlyphIDs-in numerical order */
+	RangeRecord RangeArray[1/*RangeCount*/]; /* Array of GlyphIDs-in numerical order */
     } CoverageFormat2;
     int i, j;
     GSUB gsub;
@@ -796,7 +796,7 @@
 			cov.CoverageFormat = coverage_format; /* Debug purpose only. */
 			cov.GlyphCount = U16(coverage_ptr + offset_of(CoverageFormat1, GlyphCount));
 			{   /* Binary search. */
-			    int k0 = 0, k1 = subst.GlyphCount;
+			    int k0 = 0, k1 = cov.GlyphCount;
 
 			    for (;;) {
 				int k = (k0 + k1) / 2;
@@ -804,7 +804,7 @@
 							 + sizeof(GlyphID) * k);
 				if (glyph_index == glyph) {
 				    /* Found. */
-				    if (k >= subst.GlyphCount)
+				    if (k >= cov.GlyphCount)
 					break; /* Wrong data ? (not sure). */
 				    else {
 					GlyphID new_glyph = U16(subtable_ptr + offset_of(SingleSubstFormat2, Substitute)
@@ -821,6 +821,45 @@
 				    k0 = k + 1;
 			    }			
 			}
+		    } else if (coverage_format == 2) {
+			CoverageFormat2 cov;
+
+			cov.CoverageFormat = coverage_format; /* Debug purpose only. */
+			cov.RangeCount = U16(coverage_ptr + offset_of(CoverageFormat2, RangeCount));
+			{   /* Binary search. */
+			    int k0 = 0, k1 = cov.RangeCount;
+
+			    for (;;) {
+				int k = (k0 + k1) / 2;
+				RangeRecord rr;
+
+				rr.Start = U16(coverage_ptr + offset_of(CoverageFormat2, RangeArray)
+					+ sizeof(RangeRecord) * k  + offset_of(RangeRecord, Start));
+				rr.End = U16(coverage_ptr + offset_of(CoverageFormat2, RangeArray)
+					+ sizeof(RangeRecord) * k  + offset_of(RangeRecord, End));
+				rr.StartCoverageIndex = U16(coverage_ptr + offset_of(CoverageFormat2, RangeArray)
+					+ sizeof(RangeRecord) * k  + offset_of(RangeRecord, StartCoverageIndex));
+
+				if (rr.Start <= glyph_index && glyph_index <= rr.End) {
+				    /* Found. */
+				    if (k >= cov.RangeCount)
+					break; /* Wrong data ? (not sure). */
+				    else {
+					uint16_t subst_index = rr.StartCoverageIndex + (glyph_index - rr.Start);
+					GlyphID new_glyph = U16(subtable_ptr + offset_of(SingleSubstFormat2, Substitute)
+							    + sizeof(GlyphID) * subst_index);
+
+					return new_glyph;
+				    }
+				} else if (k0 >= k1 - 1) {
+				    k += 0; /* A place for breakpoint. */
+				    break; /* Not found. */
+				} else if (glyph_index < rr.Start)
+				    k1 = k;
+				else
+				    k0 = k + 1;
+			    }			
+			}
 		    } else {
 			/* Not implemented yet. */
 		    }



More information about the gs-cvs mailing list