|
From: <ai...@us...> - 2010-04-27 21:53:15
|
Revision: 10939
http://plplot.svn.sourceforge.net/plplot/?rev=10939&view=rev
Author: airwin
Date: 2010-04-27 21:53:09 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
If standard font lookup fails for this Type 1 font device, then as "last
chance" switch to Type 1 symbol font and try again. But if that "last
chance" lookup also fails, then accept a blank result and move on.
This fix appears to give good results for examples 3, 6, 7, and 23. For the
examples 6 and 7 tests where hrshsym has an effect, I used -drvopt hrshsym=0
(which avoids Hershey fonts for plpoin and plsym). I also used the
-DHERSHEY_FALLBACK=OFF cmake option which replaces Hershey glyphs that do
not have a recognized unicode equivalent with a blank. Thus, in all cases
Type 1 fonts were used for these tests rather than Hershey fonts.
ToDo. Equivalent changes for the other Type1 font device driver (i.e.,
the ps device driver).
Modified Paths:
--------------
trunk/drivers/pdf.c
Modified: trunk/drivers/pdf.c
===================================================================
--- trunk/drivers/pdf.c 2010-04-27 21:39:41 UTC (rev 10938)
+++ trunk/drivers/pdf.c 2010-04-27 21:53:09 UTC (rev 10939)
@@ -85,7 +85,7 @@
/* font variables */
HPDF_Font m_font;
- int nlookup;
+ int nlookup, if_symbol_font;
const Unicode_to_Type1_table *lookup;
HPDF_REAL fontSize;
HPDF_REAL fontScale;
@@ -504,16 +504,16 @@
/* jlo is invalid or it is valid and index > lookup[jlo].Unicode.
* jhi is invalid or it is valid and index < lookup[jhi].Unicode.
* All these conditions together imply index cannot be found in lookup.
- * Mark with 32 (which is normally a blank in type 1 fonts).
+ * Mark with ' ' (which is normally the index for blank in type 1 fonts).
*/
- return ( 32 );
+ return ( ' ' );
}
/***********************************************************************
* PSDrawTextToCanvas( pdfdev* dev, unsigned char* type1_string, short drawText )
*
- * This function determines the extend of the string and does
+ * This function determines the extent of the string and does
* the actual drawing to the page if drawText is true.
***********************************************************************/
void PSDrawTextToCanvas( pdfdev* dev, unsigned char* type1_string, short drawText )
@@ -550,30 +550,36 @@
{
char *font;
- /* convert the fci to Base14/Type1 font information */
- font = plP_FCI2FontName( fci, Type1Lookup, N_Type1Lookup );
+ // fci = 0 is a special value indicating the Type 1 Symbol font
+ // is desired. This value cannot be confused with a normal FCI value
+ // because it doesn't have the PL_FCI_MARK.
+ if ( fci == 0)
+ {
+ font = "Symbol";
+ dev->nlookup = number_of_entries_in_unicode_to_symbol_table;
+ dev->lookup = unicode_to_symbol_lookup_table;
+ dev->if_symbol_font = 1;
+ }
+ else
+ {
+ /* convert the fci to Base14/Type1 font information */
+ font = plP_FCI2FontName( fci, Type1Lookup, N_Type1Lookup );
+ dev->nlookup = number_of_entries_in_unicode_to_standard_table;
+ dev->lookup = unicode_to_standard_lookup_table;
+ dev->if_symbol_font = 0;
+ }
if ( !( dev->m_font = HPDF_GetFont( dev->pdf, font, NULL ) ) )
plexit( "ERROR: Couldn't open font\n" );
HPDF_Page_SetFontAndSize( dev->page, dev->m_font, dev->fontSize * dev->fontScale );
- if ( !strcmp( font, "Symbol" ) )
- {
- dev->nlookup = number_of_entries_in_unicode_to_symbol_table;
- dev->lookup = unicode_to_symbol_lookup_table;
- }
- else
- {
- dev->nlookup = number_of_entries_in_unicode_to_standard_table;
- dev->lookup = unicode_to_standard_lookup_table;
- }
}
/***********************************************************************
* PSDrawText( pdfdev* dev, PLUNICODE* ucs4, int ucs4Len, short drawText )
*
- * This function is called twice, first to determine the extend of the
+ * This function is called twice, first to determine the extent of the
* text written to the page and then a second time to actually draw
* the text.
***********************************************************************/
@@ -583,13 +589,14 @@
unsigned char type1_string[MAX_STRING_LEN];
char plplotEsc;
PLUNICODE fci;
+ int last_chance = 0;
memset( type1_string, '\0', MAX_STRING_LEN );
/* Get PLplot escape character */
plgesc( &plplotEsc );
- /* Get the curent font */
+ /* Get the current font */
dev->fontScale = 1.0;
dev->yOffset = 0.0;
plgfci( &fci );
@@ -604,16 +611,108 @@
{
if ( ucs4[i] != (PLUNICODE) plplotEsc ) /* a character to display */
{
- type1_string[s++] = plunicode2type1( ucs4[i], dev->lookup, dev->nlookup );
- i++;
- continue;
+ type1_string[s] = plunicode2type1( ucs4[i], dev->lookup, dev->nlookup );
+ if(ucs4[i] != ' ' && type1_string[s] == ' ')
+ {
+ // failed lookup
+ if(! dev->if_symbol_font)
+ {
+ // failed standard font lookup. Try "last chance"
+ // symbol font instead.
+ type1_string[s] = '\0';
+ PSDrawTextToCanvas( dev, type1_string, drawText );
+ s = 0;
+ last_chance = 1;
+ PSSetFont( dev, 0 );
+ continue;
+ }
+ else if(!last_chance)
+ {
+ // failed symbol font lookup that is not right
+ // after a failed standard font lookup (i.e.,
+ // last_change = 0). Try standard fonts lookup instead.
+ type1_string[s] = '\0';
+ PSDrawTextToCanvas( dev, type1_string, drawText );
+ s = 0;
+ last_chance = 0;
+ PSSetFont( dev, fci );
+ continue;
+ }
+ else
+ {
+ // failed "last_chance" symbol font lookup that
+ // has occurred right after a failed standard
+ // fonts lookup. Just accept blank result and
+ // move on using standard fonts.
+ PSDrawTextToCanvas( dev, type1_string, drawText );
+ s = 0;
+ last_chance = 0;
+ PSSetFont( dev, fci );
+ i++;
+ continue;
+ }
+ }
+ else
+ {
+ // font lookup succeeded.
+ s++;
+ i++;
+ last_chance = 0;
+ continue;
+ }
}
i++;
if ( ucs4[i] == (PLUNICODE) plplotEsc ) /* a escape character to display */
{
- type1_string[s++] = plunicode2type1( ucs4[i], dev->lookup, dev->nlookup );
- i++;
- continue;
+ type1_string[s] = plunicode2type1( ucs4[i], dev->lookup, dev->nlookup );
+ if(ucs4[i] != ' ' && type1_string[s] == ' ')
+ {
+ // failed lookup
+ if(! dev->if_symbol_font)
+ {
+ // failed standard font lookup. Try "last chance"
+ // symbol font instead.
+ type1_string[s] = '\0';
+ PSDrawTextToCanvas( dev, type1_string, drawText );
+ s = 0;
+ last_chance = 1;
+ PSSetFont( dev, 0 );
+ continue;
+ }
+ else if(!last_chance)
+ {
+ // failed symbol font lookup that is not right
+ // after a failed standard font lookup (i.e.,
+ // last_change = 0). Try standard fonts lookup instead.
+ type1_string[s] = '\0';
+ PSDrawTextToCanvas( dev, type1_string, drawText );
+ s = 0;
+ last_chance = 0;
+ PSSetFont( dev, fci );
+ continue;
+ }
+ else
+ {
+ // failed "last_chance" symbol font lookup that
+ // has occurred right after a failed standard
+ // fonts lookup. Just accept blank result and
+ // move on using standard fonts.
+ PSDrawTextToCanvas( dev, type1_string, drawText );
+ s = 0;
+ last_chance = 0;
+ PSSetFont( dev, fci );
+ i++;
+ continue;
+ }
+ }
+ else
+ {
+ // font lookup succeeded.
+ s++;
+ i++;
+ last_chance = 0;
+ continue;
+ }
}
else
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|