From: <ai...@us...> - 2011-07-10 17:27:06
|
Revision: 11804 http://plplot.svn.sourceforge.net/plplot/?rev=11804&view=rev Author: airwin Date: 2011-07-10 17:27:00 +0000 (Sun, 10 Jul 2011) Log Message: ----------- Use plP_script_scale method to replace idiosyncratic method of determining superscript/subscript font sizes and offsets. The test_superscript_subscript.py results are much improved by this change. However, a vertical offset issue for the pdf device driver that was evident before this change still continues; superscript offsets shift the entire string downwards (including all text before when "#u" is used) while the corresponding result for subscripts (when "#d" is used) has no such effect. I have looked hard for the origin of this pdf bug but cannot find the source of it. The superscript and subscript paths are absolutely identical in the code except for the numerical calculation of dev->yOffset. So why does the correct offset from the baseline being calculated in both cases affect the overall baseline (including the unsuperscripted/unsubscripted _prior_ parts of the string) in the superscript case but not in the subscript case? Modified Paths: -------------- trunk/drivers/pdf.c Modified: trunk/drivers/pdf.c =================================================================== --- trunk/drivers/pdf.c 2011-07-10 17:08:00 UTC (rev 11803) +++ trunk/drivers/pdf.c 2011-07-10 17:27:00 UTC (rev 11804) @@ -579,6 +579,13 @@ HPDF_Page_SetFontAndSize( dev->page, dev->m_font, dev->fontSize * dev->fontScale ); } +// 0.8 should mimic the offset of first superscript/subscript level +// implemented in plstr (plsym.c) for Hershey fonts. However, when +// comparing with -dev xwin and -dev xcairo results changing this +// factor to 0.6 appears to offset the centers of the letters +// appropriately while 0.8 gives much poorer agreement with the +// other devices. +# define RISE_FACTOR 0.6 //-------------------------------------------------------------------------- // PSDrawText( pdfdev* dev, PLUNICODE* ucs4, int ucs4Len, short drawText ) @@ -594,6 +601,8 @@ char plplotEsc; PLUNICODE fci; int last_chance = 0; + PLFLT old_sscale, sscale, old_soffset, soffset, dup; + PLINT level = 0; memset( type1_string, '\0', MAX_STRING_LEN ); @@ -721,34 +730,38 @@ else { if ( ucs4[i] == (PLUNICODE) 'u' ) // Superscript - { // draw string so far + { + // draw string so far PSDrawTextToCanvas( dev, type1_string, drawText ); s = 0; - // change font scale - if ( dev->yOffset < 0.0 ) - dev->fontScale *= (HPDF_REAL) 1.25; // Subscript scaling parameter - else - dev->fontScale *= (HPDF_REAL) 0.8; // Subscript scaling parameter + plP_script_scale( TRUE, &level, + &old_sscale, &sscale, &old_soffset, &soffset ); + // The correction for the difference in magnitude + // between the baseline and middle coordinate systems + // for superscripts should be + // 0.5*(base font size - superscript/subscript font size). + dup = 0.5 * ( 1.0 - sscale ); + dev->fontScale = sscale; PSSetFont( dev, fci ); - - dev->yOffset += dev->fontSize * dev->fontScale / (HPDF_REAL) 2.; + dev->yOffset = dev->fontSize * ( soffset * RISE_FACTOR + dup ); } if ( ucs4[i] == (PLUNICODE) 'd' ) // Subscript { - HPDF_REAL old_fontScale = dev->fontScale; // draw string so far PSDrawTextToCanvas( dev, type1_string, drawText ); s = 0; - // change font scale - if ( dev->yOffset > 0.0 ) - dev->fontScale *= (HPDF_REAL) 1.25; // Subscript scaling parameter - else - dev->fontScale *= (HPDF_REAL) 0.8; // Subscript scaling parameter + plP_script_scale( FALSE, &level, + &old_sscale, &sscale, &old_soffset, &soffset ); + // The correction for the difference in magnitude + // between the baseline and middle coordinate systems + // for subcripts should be + // 0.5*(base font size - superscript/subscript font size). + dup = -0.5 * ( 1.0 - sscale ); + dev->fontScale = sscale; PSSetFont( dev, fci ); - - dev->yOffset -= dev->fontSize * old_fontScale / (HPDF_REAL) 2.; + dev->yOffset = -dev->fontSize * ( soffset * RISE_FACTOR + dup ); } if ( ucs4[i] == (PLUNICODE) '-' ) // underline { // draw string so far This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |