From: <ai...@us...> - 2011-07-03 17:06:24
|
Revision: 11783 http://plplot.svn.sourceforge.net/plplot/?rev=11783&view=rev Author: airwin Date: 2011-07-03 17:06:18 +0000 (Sun, 03 Jul 2011) Log Message: ----------- Implement a private plP_script_scale function that calculates scale values for font size and magnitude of the vertical offset associated with superscripts/subscripts. Currently, the font scale and offset calculations associated with superscripts and subscripts are done in an idiosyncratic (and often incorrect) way in various locations within the core code and drivers. plP_script_scale is designed to consolidate those bits of logic in one place where the calculation is done correctly. As a first use of this new logic, use plP_script_scale for the Hershey font superscripts/subscripts. plP_script_scale produces completely symmetrical vertical offsets between superscripts and subscripts. Therefore, this change corrects a very long-standing error (since before 1993) in the vertical offset of the Hershey subscripts which previously were not consistent with the magnitude of the vertical offsets of the superscripts. Modified Paths: -------------- trunk/include/plplotP.h trunk/src/plsym.c Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2011-07-01 06:27:21 UTC (rev 11782) +++ trunk/include/plplotP.h 2011-07-03 17:06:18 UTC (rev 11783) @@ -620,6 +620,14 @@ PLDLLIMPEXP void difilt_clip( PLINT *, PLINT * ); +// Calculate scale of font size and scale of magnitude of vertical +// offset associated with superscripts and subscripts. + +PLDLLIMPEXP void +plP_script_scale( PLBOOL ifupper, PLINT *level, + PLFLT *old_scale, PLFLT *scale, + PLFLT *old_offset, PLFLT *offset); + // Driver draws text void Modified: trunk/src/plsym.c =================================================================== --- trunk/src/plsym.c 2011-07-01 06:27:21 UTC (rev 11782) +++ trunk/src/plsym.c 2011-07-03 17:06:18 UTC (rev 11783) @@ -787,6 +787,7 @@ PLINT ch, i, length, level = 0, style, oline = 0, uline = 0; PLFLT width = 0., xorg = 0., yorg = 0., def, ht, dscale, scale; + PLFLT old_sscale, sscale, old_soffset, soffset; plgchr( &def, &ht ); dscale = 0.05 * ht; @@ -802,17 +803,19 @@ for ( i = 0; i < length; i++ ) { ch = symbol[i]; - if ( ch == -1 ) // super-script + if ( ch == -1 ) // superscript { - level++; - yorg += 16.0 * scale; - scale = dscale * pow( 0.75, (double) ABS( level ) ); + plP_script_scale( TRUE, &level, + &old_sscale, &sscale, &old_soffset, &soffset); + yorg = 16.0*dscale*soffset; + scale = dscale * sscale; } - else if ( ch == -2 ) // sub-script + else if ( ch == -2 ) // subscript { - level--; - scale = dscale * pow( 0.75, (double) ABS( level ) ); - yorg -= 16.0 * scale; + plP_script_scale( FALSE, &level, + &old_sscale, &sscale, &old_soffset, &soffset); + yorg = -16.0*dscale*soffset; + scale = dscale * sscale; } else if ( ch == -3 ) // back-char xorg -= width * scale; @@ -1229,6 +1232,74 @@ } //-------------------------------------------------------------------------- +//! Calculate scale of font size and scale of magnitude of vertical +//! offset associated with superscripts and subscripts. +//! Notes on arguments: ifupper must be either TRUE or FALSE on every +//! call to plP_script_scale. The contents of the location pointed to +//! by the level pointer must be zero on the first call to +//! plP_script_scale, but not modified externally from then on. The +//! contents of the locations pointed to by all other pointer +//! arguments are initialized internally, and should not be modified +//! externally. +//! +//! @param ifupper Value which is TRUE if superscripting, i.e., if +//! incrementing the previous level, and FALSE if subscripting, i.e., +//! decrementing the previous level. +//! @param level Pointer to a location which contains the value of the +//! superscript/subscript level. That value is 0, +-1, +-2, etc., for +//! no superscript/subscript, the first level of +//! superscript/subscript, the second level of superscript/subscript, +//! etc. Before the call the value is the old level, and after the +//! call the value will be incremented (ifupper TRUE) or decremented +//! (ifupper FALSE) from the previous value. +//! @param old_scale A pointer to a location that contains after the +//! call the old font size scale value. +//! @param scale A pointer to a location that contains after the call +//! the font size scale value. This value is 0.75^{|level|} where +//! |level| is the magnitude of the value of the superscript/subscript +//! level after the call. +//! @param old_offset A pointer to a location that contains after the +//! call the old value of the magnitude of the superscript/subscript +//! offset. +//! @param offset A pointer to a location that contains after the call +//! the value of the magnitude of the superscript/subscript offset +//! which is zero for |level|=0 and sum_{i=1}^{i=|level|} 0.75^{i-1}, +//! otherwise. + +void +plP_script_scale( PLBOOL ifupper, PLINT *level, + PLFLT *old_scale, PLFLT *scale, + PLFLT *old_offset, PLFLT *offset) +{ + if (*level == 0) + { + *old_scale = 1.; + *old_offset = 0.; + } + else + { + *old_scale = *scale; + *old_offset = *offset; + } + if((*level >=0 && ifupper) || (*level <=0 && !ifupper)) + { + // If superscript of subscript moves further away from centerline.... + *scale = 0.75 * *old_scale; + *offset = *old_offset + *old_scale; + } + else + { + // If superscript of subscript moves closer to centerline.... + *scale = *old_scale/0.75; + *offset = *old_offset - *scale; + } + if(ifupper) + (*level)++; + else + (*level)--; +} + +//-------------------------------------------------------------------------- // void c_plfont(ifont) // // Sets the global font flag to 'ifont'. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |