summaryrefslogtreecommitdiff
path: root/gs/base/gschar0.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-19 23:49:56 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-19 23:49:56 +0200
commit781969994b5381ba4bed03beef217f9bde6e7c58 (patch)
treeaede27c7532f0fbe82f03dc0c04c9316be510fd5 /gs/base/gschar0.c
parent0b17959f31afe3baffbc328e7f92e88e634ad8b8 (diff)
Indent with spaces and strip trailing whitespace.
Diffstat (limited to 'gs/base/gschar0.c')
-rw-r--r--gs/base/gschar0.c566
1 files changed, 283 insertions, 283 deletions
diff --git a/gs/base/gschar0.c b/gs/base/gschar0.c
index 058ff09eb..6e3b71feb 100644
--- a/gs/base/gschar0.c
+++ b/gs/base/gschar0.c
@@ -1,6 +1,6 @@
/* Copyright (C) 2001-2006 Artifex Software, Inc.
All Rights Reserved.
-
+
This software is provided AS-IS with no warranty, either express or
implied.
@@ -34,18 +34,18 @@ gs_stack_modal_fonts(gs_text_enum_t *pte)
gs_font *cfont = pte->fstack.items[fdepth].font;
while (cfont->FontType == ft_composite) {
- gs_font_type0 *const cmfont = (gs_font_type0 *) cfont;
-
- if (!fmap_type_is_modal(cmfont->data.FMapType))
- break;
- if (fdepth == MAX_FONT_STACK)
- return_error(gs_error_invalidfont);
- fdepth++;
- cfont = cmfont->data.FDepVector[cmfont->data.Encoding[0]];
- pte->fstack.items[fdepth].font = cfont;
- pte->fstack.items[fdepth - 1].index = 0;
- if_debug2('j', "[j]stacking depth=%d font=0x%lx\n",
- fdepth, (ulong) cfont);
+ gs_font_type0 *const cmfont = (gs_font_type0 *) cfont;
+
+ if (!fmap_type_is_modal(cmfont->data.FMapType))
+ break;
+ if (fdepth == MAX_FONT_STACK)
+ return_error(gs_error_invalidfont);
+ fdepth++;
+ cfont = cmfont->data.FDepVector[cmfont->data.Encoding[0]];
+ pte->fstack.items[fdepth].font = cfont;
+ pte->fstack.items[fdepth - 1].index = 0;
+ if_debug2('j', "[j]stacking depth=%d font=0x%lx\n",
+ fdepth, (ulong) cfont);
}
pte->fstack.depth = fdepth;
return 0;
@@ -56,9 +56,9 @@ int
gs_type0_init_fstack(gs_text_enum_t *pte, gs_font * pfont)
{
if (!(pte->text.operation & (TEXT_FROM_STRING | TEXT_FROM_BYTES)))
- return_error(gs_error_invalidfont);
+ return_error(gs_error_invalidfont);
if_debug1('j', "[j]stacking depth=0 font=0x%lx\n",
- (ulong) pfont);
+ (ulong) pfont);
pte->fstack.depth = 0;
pte->fstack.items[0].font = pfont;
pte->fstack.items[0].index = 0;
@@ -127,132 +127,132 @@ gs_type0_next_char_glyph(gs_text_enum_t *pte, gs_char *pchr, gs_glyph *pglyph)
*/
if (pte->index == 0) {
- int idepth = 0;
-
- pfont = pte->fstack.items[0].font;
- for (; pfont->FontType == ft_composite;) {
- fmap_type fmt = (pdata = &pfont0->data)->FMapType;
-
- if (p == end)
- return 2;
- chr = *p;
- switch (fmt) {
- case fmap_escape:
- if (chr != root_esc_char(pte))
- break;
- need_left(2);
- fidx = p[1];
- p += 2;
- if_debug1('j', "[j]from root: escape %d\n", fidx);
- rdown:select_descendant(pfont, pdata, fidx, idepth);
- if_debug2('j', "[j]... new depth=%d, new font=0x%lx\n",
- idepth, (ulong) pfont);
- continue;
- case fmap_double_escape:
- if (chr != root_esc_char(pte))
- break;
- need_left(2);
- fidx = p[1];
- p += 2;
- if (fidx == chr) {
- need_left(1);
- fidx = *p++ + 256;
- }
- if_debug1('j', "[j]from root: double escape %d\n", fidx);
- goto rdown;
- case fmap_shift:
- if (chr == pdata->ShiftIn)
- fidx = 0;
- else if (chr == pdata->ShiftOut)
- fidx = 1;
- else
- break;
- p++;
- if_debug1('j', "[j]from root: shift %d\n", fidx);
- goto rdown;
- default:
- break;
- }
- break;
- }
- /* If we saw any initial escapes or shifts, */
- /* compute a new initial base font. */
- if (idepth != 0) {
- int code;
-
- pte->fstack.depth = idepth;
- code = gs_stack_modal_fonts(pte);
- if (code < 0)
- return code;
- if (pte->fstack.depth > idepth)
- changed = 1;
- orig_depth = fdepth = pte->fstack.depth;
- }
+ int idepth = 0;
+
+ pfont = pte->fstack.items[0].font;
+ for (; pfont->FontType == ft_composite;) {
+ fmap_type fmt = (pdata = &pfont0->data)->FMapType;
+
+ if (p == end)
+ return 2;
+ chr = *p;
+ switch (fmt) {
+ case fmap_escape:
+ if (chr != root_esc_char(pte))
+ break;
+ need_left(2);
+ fidx = p[1];
+ p += 2;
+ if_debug1('j', "[j]from root: escape %d\n", fidx);
+ rdown:select_descendant(pfont, pdata, fidx, idepth);
+ if_debug2('j', "[j]... new depth=%d, new font=0x%lx\n",
+ idepth, (ulong) pfont);
+ continue;
+ case fmap_double_escape:
+ if (chr != root_esc_char(pte))
+ break;
+ need_left(2);
+ fidx = p[1];
+ p += 2;
+ if (fidx == chr) {
+ need_left(1);
+ fidx = *p++ + 256;
+ }
+ if_debug1('j', "[j]from root: double escape %d\n", fidx);
+ goto rdown;
+ case fmap_shift:
+ if (chr == pdata->ShiftIn)
+ fidx = 0;
+ else if (chr == pdata->ShiftOut)
+ fidx = 1;
+ else
+ break;
+ p++;
+ if_debug1('j', "[j]from root: shift %d\n", fidx);
+ goto rdown;
+ default:
+ break;
+ }
+ break;
+ }
+ /* If we saw any initial escapes or shifts, */
+ /* compute a new initial base font. */
+ if (idepth != 0) {
+ int code;
+
+ pte->fstack.depth = idepth;
+ code = gs_stack_modal_fonts(pte);
+ if (code < 0)
+ return code;
+ if (pte->fstack.depth > idepth)
+ changed = 1;
+ orig_depth = fdepth = pte->fstack.depth;
+ }
}
/* Handle initial escapes or shifts. */
up:if (p == end)
- return 2;
+ return 2;
chr = *p;
while (fdepth > 0) {
- pfont = pte->fstack.items[fdepth - 1].font;
- pdata = &pfont0->data;
- switch (pdata->FMapType) {
- default: /* non-modal */
- fdepth--;
- continue;
-
- case fmap_escape:
- if (chr != root_esc_char(pte))
- break;
- need_left(2);
- fidx = *++p;
- if_debug1('j', "[j]next: escape %d\n", fidx);
- /* Per Adobe, if we get an escape at the root, */
- /* treat it as an ordinary character (font index). */
- if (fidx == chr && fdepth > 1) {
- fdepth--;
- goto up;
- }
- down:if (++p == end)
- return 2;
- chr = *p;
- fdepth--;
- do {
- select_descendant(pfont, pdata, fidx, fdepth);
- if_debug3('j', "[j]down from modal: new depth=%d, index=%d, new font=0x%lx\n",
- fdepth, fidx, (ulong) pfont);
- if (pfont->FontType != ft_composite)
- break;
- pdata = &pfont0->data;
- fidx = 0;
- }
- while (pdata->FMapType == fmap_escape);
- continue;
-
- case fmap_double_escape:
- if (chr != root_esc_char(pte))
- break;
- need_left(2);
- fidx = *++p;
- if (fidx == chr) {
- need_left(2);
- fidx = *++p + 256;
- }
- if_debug1('j', "[j]next: double escape %d\n", fidx);
- goto down;
-
- case fmap_shift:
- if (chr == pdata->ShiftIn)
- fidx = 0;
- else if (chr == pdata->ShiftOut)
- fidx = 1;
- else
- break;
- if_debug1('j', "[j]next: shift %d\n", fidx);
- goto down;
- }
- break;
+ pfont = pte->fstack.items[fdepth - 1].font;
+ pdata = &pfont0->data;
+ switch (pdata->FMapType) {
+ default: /* non-modal */
+ fdepth--;
+ continue;
+
+ case fmap_escape:
+ if (chr != root_esc_char(pte))
+ break;
+ need_left(2);
+ fidx = *++p;
+ if_debug1('j', "[j]next: escape %d\n", fidx);
+ /* Per Adobe, if we get an escape at the root, */
+ /* treat it as an ordinary character (font index). */
+ if (fidx == chr && fdepth > 1) {
+ fdepth--;
+ goto up;
+ }
+ down:if (++p == end)
+ return 2;
+ chr = *p;
+ fdepth--;
+ do {
+ select_descendant(pfont, pdata, fidx, fdepth);
+ if_debug3('j', "[j]down from modal: new depth=%d, index=%d, new font=0x%lx\n",
+ fdepth, fidx, (ulong) pfont);
+ if (pfont->FontType != ft_composite)
+ break;
+ pdata = &pfont0->data;
+ fidx = 0;
+ }
+ while (pdata->FMapType == fmap_escape);
+ continue;
+
+ case fmap_double_escape:
+ if (chr != root_esc_char(pte))
+ break;
+ need_left(2);
+ fidx = *++p;
+ if (fidx == chr) {
+ need_left(2);
+ fidx = *++p + 256;
+ }
+ if_debug1('j', "[j]next: double escape %d\n", fidx);
+ goto down;
+
+ case fmap_shift:
+ if (chr == pdata->ShiftIn)
+ fidx = 0;
+ else if (chr == pdata->ShiftOut)
+ fidx = 1;
+ else
+ break;
+ if_debug1('j', "[j]next: shift %d\n", fidx);
+ goto down;
+ }
+ break;
}
/* At this point, chr == *p. */
/* (This is important to know for CMap'ed fonts.) */
@@ -268,98 +268,98 @@ gs_type0_next_char_glyph(gs_text_enum_t *pte, gs_char *pchr, gs_glyph *pglyph)
*/
while ((pfont = pte->fstack.items[fdepth].font)->FontType == ft_composite) {
- pdata = &pfont0->data;
- switch (pdata->FMapType) {
- default: /* can't happen */
- return_error(gs_error_invalidfont);
-
- case fmap_8_8:
- need_left(1);
- fidx = chr;
- chr = *p++;
- if_debug2('J', "[J]8/8 index=%d, char=%ld\n",
- fidx, chr);
- break;
-
- case fmap_1_7:
- fidx = chr >> 7;
- chr &= 0x7f;
- if_debug2('J', "[J]1/7 index=%d, char=%ld\n",
- fidx, chr);
- break;
-
- case fmap_9_7:
- need_left(1);
- fidx = ((uint) chr << 1) + (*p >> 7);
- chr = *p & 0x7f;
- if_debug2('J', "[J]9/7 index=%d, char=%ld\n",
- fidx, chr);
- p++;
- break;
-
- case fmap_SubsVector:
- {
- int width = pdata->subs_width;
- uint subs_count = pdata->subs_size;
- const byte *psv = pdata->SubsVector.data;
+ pdata = &pfont0->data;
+ switch (pdata->FMapType) {
+ default: /* can't happen */
+ return_error(gs_error_invalidfont);
+
+ case fmap_8_8:
+ need_left(1);
+ fidx = chr;
+ chr = *p++;
+ if_debug2('J', "[J]8/8 index=%d, char=%ld\n",
+ fidx, chr);
+ break;
+
+ case fmap_1_7:
+ fidx = chr >> 7;
+ chr &= 0x7f;
+ if_debug2('J', "[J]1/7 index=%d, char=%ld\n",
+ fidx, chr);
+ break;
+
+ case fmap_9_7:
+ need_left(1);
+ fidx = ((uint) chr << 1) + (*p >> 7);
+ chr = *p & 0x7f;
+ if_debug2('J', "[J]9/7 index=%d, char=%ld\n",
+ fidx, chr);
+ p++;
+ break;
+
+ case fmap_SubsVector:
+ {
+ int width = pdata->subs_width;
+ uint subs_count = pdata->subs_size;
+ const byte *psv = pdata->SubsVector.data;
#define subs_loop(subs_elt, width)\
while ( subs_count != 0 && tchr >= (schr = subs_elt) )\
subs_count--, tchr -= schr, psv += width;\
chr = tchr; p += width - 1; break
- switch (width) {
- default: /* can't happen */
- return_error(gs_error_invalidfont);
- case 1:
- {
- byte tchr = (byte) chr, schr;
-
- subs_loop(*psv, 1);
- }
- case 2:
- need_left(1);
+ switch (width) {
+ default: /* can't happen */
+ return_error(gs_error_invalidfont);
+ case 1:
+ {
+ byte tchr = (byte) chr, schr;
+
+ subs_loop(*psv, 1);
+ }
+ case 2:
+ need_left(1);
#define w2(p) (((ushort)*p << 8) + p[1])
- {
- ushort tchr = ((ushort) chr << 8) + *p,
- schr;
-
- subs_loop(w2(psv), 2);
- }
- case 3:
- need_left(2);
+ {
+ ushort tchr = ((ushort) chr << 8) + *p,
+ schr;
+
+ subs_loop(w2(psv), 2);
+ }
+ case 3:
+ need_left(2);
#define w3(p) (((ulong)*p << 16) + ((uint)p[1] << 8) + p[2])
- {
- ulong tchr = ((ulong) chr << 16) + w2(p),
- schr;
-
- subs_loop(w3(psv), 3);
- }
- case 4:
- need_left(3);
+ {
+ ulong tchr = ((ulong) chr << 16) + w2(p),
+ schr;
+
+ subs_loop(w3(psv), 3);
+ }
+ case 4:
+ need_left(3);
#define w4(p) (((ulong)*p << 24) + ((ulong)p[1] << 16) + ((uint)p[2] << 8) + p[3])
- {
- ulong tchr = ((ulong) chr << 24) + w3(p),
- schr;
+ {
+ ulong tchr = ((ulong) chr << 24) + w3(p),
+ schr;
- subs_loop(w4(psv), 4);
- }
+ subs_loop(w4(psv), 4);
+ }
#undef w2
#undef w3
#undef w4
#undef subs_loop
- }
- fidx = pdata->subs_size - subs_count;
- if_debug2('J', "[J]SubsVector index=%d, char=%ld\n",
- fidx, chr);
- break;
- }
-
- case fmap_CMap:
- {
- gs_const_string cstr;
- uint mindex = p - str - 1; /* p was incremented */
- int code;
+ }
+ fidx = pdata->subs_size - subs_count;
+ if_debug2('J', "[J]SubsVector index=%d, char=%ld\n",
+ fidx, chr);
+ break;
+ }
+
+ case fmap_CMap:
+ {
+ gs_const_string cstr;
+ uint mindex = p - str - 1; /* p was incremented */
+ int code;
/*
* When decoding an FMapType4 or 5, the value
@@ -369,84 +369,84 @@ gs_type0_next_char_glyph(gs_text_enum_t *pte, gs_char *pchr, gs_glyph *pglyph)
* chr. Check whether chr has been modified, and
* if so, construct and pass a modified buffer.
*/
- if (*(p - 1) != chr) {
- byte substr[MAX_CMAP_CODE_SIZE];
- int submindex = 0;
- if_debug2('j', "[j] *(p-1) 0x%02x != chr 0x%02x, modified str should be passed\n",
- *(p-1), (byte)chr);
- memcpy(substr, p - 1,
- min(MAX_CMAP_CODE_SIZE, end - p + 1));
- substr[0] = chr;
- cstr.data = substr;
- cstr.size = min(MAX_CMAP_CODE_SIZE, end - p + 1);
- if (gs_debug_c('j')) {
- dlprintf("[j] original str(");
- debug_print_string_hex(str, end - str);
- dlprintf(") -> modified substr(");
- debug_print_string_hex(cstr.data, cstr.size);
- dlprintf(")\n");
- }
- code = gs_cmap_decode_next(pdata->CMap, &cstr,
- (uint*) &submindex, &fidx, &chr, &glyph);
- mindex += submindex;
- } else {
- cstr.data = str;
- cstr.size = end - str;
- code = gs_cmap_decode_next(pdata->CMap, &cstr, &mindex,
- &fidx, &chr, &glyph);
- }
- if (code < 0)
- return code;
- pte->cmap_code = code; /* hack for widthshow */
- p = str + mindex;
- if_debug3('J', "[J]CMap returns %d, chr=0x%lx, glyph=0x%lx\n",
- code, (ulong) chr, (ulong) glyph);
- if (code == 0) {
- if (glyph == gs_no_glyph) {
- glyph = gs_min_cid_glyph;
- if_debug0('J', "... undefined\n");
- /* Must select a descendant font anyway, we can't use the type 0
- * even for the /.notdef...
- */
- select_descendant(pfont, pdata, fidx, fdepth);
- goto done;
- }
- } else
- chr = (gs_char) glyph, glyph = gs_no_glyph;
- /****** RESCAN chr IF DESCENDANT IS CMAP'ED ******/
- break;
- }
- }
-
- select_descendant(pfont, pdata, fidx, fdepth);
- if_debug2('J', "... new depth=%d, new font=0x%lx\n",
- fdepth, (ulong) pfont);
+ if (*(p - 1) != chr) {
+ byte substr[MAX_CMAP_CODE_SIZE];
+ int submindex = 0;
+ if_debug2('j', "[j] *(p-1) 0x%02x != chr 0x%02x, modified str should be passed\n",
+ *(p-1), (byte)chr);
+ memcpy(substr, p - 1,
+ min(MAX_CMAP_CODE_SIZE, end - p + 1));
+ substr[0] = chr;
+ cstr.data = substr;
+ cstr.size = min(MAX_CMAP_CODE_SIZE, end - p + 1);
+ if (gs_debug_c('j')) {
+ dlprintf("[j] original str(");
+ debug_print_string_hex(str, end - str);
+ dlprintf(") -> modified substr(");
+ debug_print_string_hex(cstr.data, cstr.size);
+ dlprintf(")\n");
+ }
+ code = gs_cmap_decode_next(pdata->CMap, &cstr,
+ (uint*) &submindex, &fidx, &chr, &glyph);
+ mindex += submindex;
+ } else {
+ cstr.data = str;
+ cstr.size = end - str;
+ code = gs_cmap_decode_next(pdata->CMap, &cstr, &mindex,
+ &fidx, &chr, &glyph);
+ }
+ if (code < 0)
+ return code;
+ pte->cmap_code = code; /* hack for widthshow */
+ p = str + mindex;
+ if_debug3('J', "[J]CMap returns %d, chr=0x%lx, glyph=0x%lx\n",
+ code, (ulong) chr, (ulong) glyph);
+ if (code == 0) {
+ if (glyph == gs_no_glyph) {
+ glyph = gs_min_cid_glyph;
+ if_debug0('J', "... undefined\n");
+ /* Must select a descendant font anyway, we can't use the type 0
+ * even for the /.notdef...
+ */
+ select_descendant(pfont, pdata, fidx, fdepth);
+ goto done;
+ }
+ } else
+ chr = (gs_char) glyph, glyph = gs_no_glyph;
+ /****** RESCAN chr IF DESCENDANT IS CMAP'ED ******/
+ break;
+ }
+ }
+
+ select_descendant(pfont, pdata, fidx, fdepth);
+ if_debug2('J', "... new depth=%d, new font=0x%lx\n",
+ fdepth, (ulong) pfont);
}
done:
/* FontBBox may be used as metrics2 with WMode=1 :
*/
if (pte->fstack.items[fdepth].font->FontType == ft_CID_encrypted ||
- pte->fstack.items[fdepth].font->FontType == ft_CID_TrueType
- ) {
- gs_font_base *pfb = (gs_font_base *)pte->fstack.items[fdepth].font;
+ pte->fstack.items[fdepth].font->FontType == ft_CID_TrueType
+ ) {
+ gs_font_base *pfb = (gs_font_base *)pte->fstack.items[fdepth].font;
- pte->FontBBox_as_Metrics2 = pfb->FontBBox.q;
+ pte->FontBBox_as_Metrics2 = pfb->FontBBox.q;
}
/* Set fstack.items[fdepth].index to CIDFont FDArray index or 0 otherwise */
fidx = 0;
if (pte->fstack.items[fdepth].font->FontType == ft_CID_encrypted) {
- int code, font_index;
- pfont = pte->fstack.items[fdepth].font;
- code = ((gs_font_cid0 *)pfont)->cidata.glyph_data((gs_font_base *)pfont,
- glyph, NULL, &font_index);
- if (code < 0) { /* failed to load glyph data, reload glyph for CID 0 */
- code = ((gs_font_cid0 *)pfont)->cidata.glyph_data((gs_font_base *)pfont,
- (gs_glyph)(gs_min_cid_glyph + 0), NULL, &font_index);
- if (code < 0)
- return_error(gs_error_invalidfont);
- }
- fidx = (uint)font_index;
+ int code, font_index;
+ pfont = pte->fstack.items[fdepth].font;
+ code = ((gs_font_cid0 *)pfont)->cidata.glyph_data((gs_font_base *)pfont,
+ glyph, NULL, &font_index);
+ if (code < 0) { /* failed to load glyph data, reload glyph for CID 0 */
+ code = ((gs_font_cid0 *)pfont)->cidata.glyph_data((gs_font_base *)pfont,
+ (gs_glyph)(gs_min_cid_glyph + 0), NULL, &font_index);
+ if (code < 0)
+ return_error(gs_error_invalidfont);
+ }
+ fidx = (uint)font_index;
if (!changed && pte->fstack.items[fdepth].index != fidx)
changed = 1;
}
@@ -457,11 +457,11 @@ done:
/* Update the pointer into the original string, but only if */
/* we didn't switch over to parsing a code from a CMap. */
if (str == pte->text.data.bytes)
- pte->index = p - str;
+ pte->index = p - str;
pte->fstack.depth = fdepth;
if_debug4('J', "[J]depth=%d font=0x%lx index=%d changed=%d\n",
- fdepth, (ulong) pte->fstack.items[fdepth].font,
- pte->fstack.items[fdepth].index, changed);
+ fdepth, (ulong) pte->fstack.items[fdepth].font,
+ pte->fstack.items[fdepth].index, changed);
return changed;
}
#undef pfont0