Re: PATCH: Fix for printing symbols and variable width underlining.


Subject: Re: PATCH: Fix for printing symbols and variable width underlining.
From: Martin Sevior (msevior@kosal0.triumf.ca)
Date: Mon Jan 10 2000 - 16:12:32 CST


On Sun, 9 Jan 2000 sterwill@abisource.com wrote:
>
> The fonts need to be declared Latin 1, or non-ASCII Latin-1 characters will
> be mapped wrong into these fonts. That "symbol" and "dingbat" fonts
> now print (but in character ranges for normal ASCII Latin-1 set glyphs)
> is a bug. They should not print, since their character encodings should
> be different.
>

I've read a bit more of the postscript manual and I now think I understand
how encoding font maps works. You are correct that not inserting the LAT
macro into the PS output stream messes up Latin fonts, on the other hand
using the LAT macro for dingbats and symbol fonts screws up what would
otherwise be a correct encoding table since the printing code dumps the
whole font plus an encoding table into every postscript file. The fix is
really simple. Simply check if the font being dump is StandardSymL or
Dingbats. If it is, don't write out the LAT. If it isn't do write out LAT.
This works fine. I've even used a hex editor to insert non-ascii but legal
characters into a postscript file and they print exactly as defined in
Appendix E of the redbook.

This is a quick fix for the two non-Latin fonts current distributed with
Abi. As abi gains more non-latin fonts we should implement a more general
way of fixing this. Maybe checking to see if a given font is in the list of
Latin fonts. If it is issue the LAT. If it isn't don't issue the LAT.

Here is the patch for src/af/xap/unix/xap_UnixPSGraphics.cpp

It also issues the "stroke" command to fix the variable width underline
printing.

The patch is included as an attachment as well as text after the "======"
line.

Martin Sevior

==========================================================================
--- xap_UnixPSGraphics.cpp Tue Jan 11 06:32:36 2000
+++ mar_xap_UnixPSGraphics.cpp Tue Jan 11 19:59:24 2000
@@ -347,17 +347,16 @@

 void PS_Graphics::drawLine(UT_sint32 x1, UT_sint32 y1, UT_sint32 x2, UT_sint32 y2)
 {
- // TODO This is used for lines in the document, as well as underlines
- // TODO and strikes.
         m_bNeedStroked = UT_TRUE;

         // emit a change in line width
+
         _emit_SetLineWidth();
-
         char buf[OUR_LINE_LIMIT*2];
 // UT_sint32 nA = getFontAscent();
- sprintf(buf,"%d %d %d %d ML\n", x2, y2, x1, y1);
+ sprintf(buf,"%d %d %d %d ML stroke \n", x2, y2, x1, y1);
         m_ps->writeBytes(buf);
+
 }

 void PS_Graphics::setLineWidth(UT_sint32 iLineWidth)
@@ -548,6 +547,12 @@

         m_ps->formatComment("PageTrailer");

+// This stroke will execute all the queued graphics commands but with the
+// cuurent graphics context. If the context changes over the page this is
+// not what you want. eg If the underline width changes over the page the
+// actual thickness of the underline used will be the last one defined.
+// A stroke should issued after every graphics command just to be safe.
+
         if(m_bNeedStroked)
                 m_ps->writeBytes("stroke\n");
         m_ps->writeBytes("EP\n");
@@ -633,13 +638,35 @@
                         m_ps->writeBytes((UT_Byte *) &ch, 1);

                 unixfont->closePFA();
-
- // after each font, change the encoding vector to ISO Latin1
- g_snprintf(buf, 128, "/%s findfont\n"
- "LAT\n"
+ // Now some code to decide if the font should use its own
+ // encoding or if we should use the ISOLatin encoding. For
+ // the time being we make the decision based on the font name.
+ // As of Jan 10th 1999 only Dingbats and StandardSymL
+ // should not use ISOLatin.
+
+ // TODO:
+ // As abi learns more non-latin languages we should implement
+ // A better way to decide whether to use Latin encoding.
+
+ if( UT_stricmp(psf->getMetricsData()->gfi->fontName,"StandardSymL")
+ == 0 ||
+ UT_stricmp(psf->getMetricsData()->gfi->fontName,"Dingbats")
+ == 0 )
+ {
+ g_snprintf(buf, 128, "/%s findfont\n"
+ "/%s EXC\n",
+ psf->getMetricsData()->gfi->fontName,
+ psf->getMetricsData()->gfi->fontName);
+ }
+
+ else
+ {
+ g_snprintf(buf, 128, "/%s findfont\n"
+ "LAT\n"
                                  "/%s EXC\n",
                                  psf->getMetricsData()->gfi->fontName,
                                  psf->getMetricsData()->gfi->fontName);
+ }
                 m_ps->writeBytes(buf);
         }

--- xap_UnixPSGraphics.cpp Tue Jan 11 06:32:36 2000
+++ mar_xap_UnixPSGraphics.cpp Tue Jan 11 19:59:24 2000
@@ -347,17 +347,16 @@

 void PS_Graphics::drawLine(UT_sint32 x1, UT_sint32 y1, UT_sint32 x2, UT_sint32 y2)
 {
- // TODO This is used for lines in the document, as well as underlines
- // TODO and strikes.
         m_bNeedStroked = UT_TRUE;

         // emit a change in line width
+
         _emit_SetLineWidth();
-
         char buf[OUR_LINE_LIMIT*2];
 // UT_sint32 nA = getFontAscent();
- sprintf(buf,"%d %d %d %d ML\n", x2, y2, x1, y1);
+ sprintf(buf,"%d %d %d %d ML stroke \n", x2, y2, x1, y1);
         m_ps->writeBytes(buf);
+
 }

 void PS_Graphics::setLineWidth(UT_sint32 iLineWidth)
@@ -548,6 +547,12 @@

         m_ps->formatComment("PageTrailer");

+// This stroke will execute all the queued graphics commands but with the
+// cuurent graphics context. If the context changes over the page this is
+// not what you want. eg If the underline width changes over the page the
+// actual thickness of the underline used will be the last one defined.
+// A stroke should issued after every graphics command just to be safe.
+
         if(m_bNeedStroked)
                 m_ps->writeBytes("stroke\n");
         m_ps->writeBytes("EP\n");
@@ -633,13 +638,35 @@
                         m_ps->writeBytes((UT_Byte *) &ch, 1);

                 unixfont->closePFA();
-
- // after each font, change the encoding vector to ISO Latin1
- g_snprintf(buf, 128, "/%s findfont\n"
- "LAT\n"
+ // Now some code to decide if the font should use its own
+ // encoding or if we should use the ISOLatin encoding. For
+ // the time being we make the decision based on the font name.
+ // As of Jan 10th 1999 only Dingbats and StandardSymL
+ // should not use ISOLatin.
+
+ // TODO:
+ // As abi learns more non-latin languages we should implement
+ // A better way to decide whether to use Latin encoding.
+
+ if( UT_stricmp(psf->getMetricsData()->gfi->fontName,"StandardSymL")
+ == 0 ||
+ UT_stricmp(psf->getMetricsData()->gfi->fontName,"Dingbats")
+ == 0 )
+ {
+ g_snprintf(buf, 128, "/%s findfont\n"
+ "/%s EXC\n",
+ psf->getMetricsData()->gfi->fontName,
+ psf->getMetricsData()->gfi->fontName);
+ }
+
+ else
+ {
+ g_snprintf(buf, 128, "/%s findfont\n"
+ "LAT\n"
                                  "/%s EXC\n",
                                  psf->getMetricsData()->gfi->fontName,
                                  psf->getMetricsData()->gfi->fontName);
+ }
                 m_ps->writeBytes(buf);
         }



This archive was generated by hypermail 2b25 : Mon Jan 10 2000 - 16:12:35 CST