! hp.sqh (hp printer support library and utilities for SQR) ! Copyright (C) 1997 Ray Ontko & Company ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! !++ ! ! Name ! ! hp.sqh ! ! Description ! ! A library of routines for controling hp printers. ! ! Included: ! ! hp_initialize use this to initialize the package ! hp_begin_bold begin bold print ! hp_end_bold end bold print ! hp_begin_italic begin italic print ! hp_end_italic end italic print ! hp_superscript print a superscipted string ! hp_subscript print a subscripted string ! hp_font_load loads a font metrics file ! hp_font_truncate truncates a string to a printable width ! hp_style_ssss set the primary font style to ssss ! hp_weight_wwww set the primary font weight to wwww ! ! The routines are described more fully below. ! !-- ! ! Author ! ! Ray Ontko ! Ray Ontko & Company ! Richmond, Indiana, USA ! (765)935-4283 ! rayo@ontko.com ! ! Modification History ! ! Name Date Comment ! ---------------- ---------- ---------------------------------------- ! Ray Ontko 1997/05/08 Created ! ! some forward declarations #IFDEF INC_HP_FONT_TRUNCATE #DEFINE HP_FONTS_ARRAY #ENDIF #IFDEF INC_HP_FONT_LOAD #DEFINE HP_FONTS_ARRAY #ENDIF !---------------------------------------------------------- hp_initialize #ifdef inc_hp_initialize #ifndef def_hp_initialize #define def_hp_initialize begin-procedure hp_initialize !++ ! ! hp_initialize ! ! Performs a variety of initializations needed by other hp routines ! in this library. If you use the hp routines, you should call this ! procedure early in your program before you use any of the other ! routines. ! ! What this procedure does: ! ! 1) Optionally, creates the hp_fonts array if HP_FONTS_ARRAY is #defined. ! The size of the hp_fonts is controled by #defining HP_FONTS_ARRAY_SIZE. ! The default size of the hp_fonts array is 2 (font 0 and font 1). ! HP_FONTS_ARRAY is automatically defined if you include hp_font_load, ! hp_font_truncate, or other routines that use the hp_fonts array. ! ! 2) Defines a number of printer control strings as global variables ! ! Primary Font Style strings: ! ! $hp_style_upright ! $hp_style_italic ! $hp_style_condensed ! $hp_style_condensed_italic ! $hp_style_compressed ! $hp_style_expanded ! $hp_style_outline ! $hp_style_inline ! $hp_style_shadowed ! $hp_style_outline_shadowed ! ! Primary Font Stroke Weight strings: ! ! $hp_weight_ultra_thin ! $hp_weight_extra_thin ! $hp_weight_thin ! $hp_weight_extra_light ! $hp_weight_light ! $hp_weight_demi_light ! $hp_weight_semi_light ! $hp_weight_medium ! $hp_weight_semi_bold ! $hp_weight_demi_bold ! $hp_weight_bold ! $hp_weight_extra_bold ! $hp_weight_black ! $hp_weight_extra_black ! $hp_weight_ultra_black ! ! These are used by procedures hp_style_upright, hp_style_italic, etc. ! !-- ! ! create fonts array ! ! Note: it would be nice to only create this if we're using the fonts ! routines. Also, we might want to calculate and store the min/max/avg ! character width, font-name, style, weight, symbol set, etc. ! #ifdef HP_FONTS_ARRAY #ifndef HP_FONTS_ARRAY_SIZE #define HP_FONTS_ARRAY_SIZE 2 #endif create-array name=hp_fonts size={HP_FONTS_ARRAY_SIZE} field=filename:char field=width:number:256 #endif ! ! Primary Style strings ! encode '<27>(s0S' into $hp_style_upright encode '<27>(s1S' into $hp_style_italic encode '<27>(s4S' into $hp_style_condensed encode '<27>(s5S' into $hp_style_condensed_italic encode '<27>(s8S' into $hp_style_compressed encode '<27>(s24S' into $hp_style_expanded encode '<27>(s32S' into $hp_style_outline encode '<27>(s64S' into $hp_style_inline encode '<27>(s128S' into $hp_style_shadowed encode '<27>(s160S' into $hp_style_outline_shadowed ! ! Primary Font Stroke Weight strings ! encode '<27>(s-7B' into $hp_weight_ultra_thin encode '<27>(s-6B' into $hp_weight_extra_thin encode '<27>(s-5B' into $hp_weight_thin encode '<27>(s-4B' into $hp_weight_extra_light encode '<27>(s-3B' into $hp_weight_light encode '<27>(s-2B' into $hp_weight_demi_light encode '<27>(s-1B' into $hp_weight_semi_light encode '<27>(s0B' into $hp_weight_medium encode '<27>(s1B' into $hp_weight_semi_bold encode '<27>(s2B' into $hp_weight_demi_bold encode '<27>(s3B' into $hp_weight_bold encode '<27>(s4B' into $hp_weight_extra_bold encode '<27>(s5B' into $hp_weight_black encode '<27>(s6B' into $hp_weight_extra_black encode '<27>(s7B' into $hp_weight_ultra_black end-procedure ! hp_initialize #endif def_hp_initialize #endif inc_hp_initialize !-------------------------------------------------------- hp_begin_italic #ifdef inc_hp_begin_italic #ifndef def_hp_begin_italic #define def_hp_begin_italic begin-procedure hp_begin_italic local !++ ! ! hp_begin_italic ! ! starts italicized text printing ! !-- encode '<27>(s1S' into $hp_style_italic print-direct nolf printer=hp $hp_style_italic end-procedure ! hp_begin_italic #endif def_hp_begin_italic #endif inc_hp_begin_italic !---------------------------------------------------------- hp_end_italic #ifdef inc_hp_end_italic #ifndef def_hp_end_italic #define def_hp_end_italic begin-procedure hp_end_italic local !++ ! ! hp_end_italic ! ! restores non-italicized text printing ! !-- encode '<27>(s0S' into $hp_style_upright print-direct nolf printer=hp $hp_style_upright end-procedure ! hp_end_italic #endif def_hp_end_italic #endif inc_hp_end_italic !---------------------------------------------------------- hp_begin_bold #ifdef inc_hp_begin_bold #ifndef def_hp_begin_bold #define def_hp_begin_bold begin-procedure hp_begin_bold local !++ ! ! hp_begin_bold ! ! starts bolded text printing ! !-- encode '<27>(s3B' into $hp_weight_bold print-direct nolf printer=hp $hp_weight_bold end-procedure ! hp_begin_bold #endif def_hp_begin_bold #endif inc_hp_begin_bold !------------------------------------------------------------ hp_end_bold #ifdef inc_hp_end_bold #ifndef def_hp_end_bold #define def_hp_end_bold begin-procedure hp_end_bold local !++ ! ! hp_end_bold ! ! restores non-bolded text printing ! !-- encode '<27>(s0B' into $hp_weight_medium print-direct nolf printer=hp $hp_style_upright end-procedure ! hp_end_bold #endif def_hp_end_bold #endif inc_hp_end_bold !--------------------------------------------------------- hp_superscript #ifdef inc_hp_superscript #ifndef def_hp_superscript #define def_hp_superscript begin-procedure hp_superscript( $str , #lin , #col ) !++ ! ! hp_superscript( $str , #lin , #col ) ! ! writes text as a superscript in a slightly smaller font. ! !-- if #lin = 0 move #_current-line to #lin end-if if #col = 0 move #_current-column to #col end-if encode '<27>' into $escape alter-printer pitch=12 let $pos = '&a' || edit( #lin * 120 - 40 , '88888' ) || 'v' || edit( #col * 72 + 288 , '88888' ) || 'H' print-direct printer=hp $escape $pos $str alter-printer pitch=10 let #pos = ceil( #col + length( $str ) * 10.0 / 12.0 ) position (#lin,#pos) end-procedure ! hp_superscript #endif def_hp_superscript #endif inc_hp_superscript !----------------------------------------------------------- hp_subscript #ifdef inc_hp_subscript #ifndef def_hp_subscript #define def_hp_subscript begin-procedure hp_subscript( $str , #lin , #col ) !++ ! ! hp_subscript( $str , #lin , #col ) ! ! writes text as a subscript in a slightly smaller font. ! !-- if #lin = 0 move #_current-line to #lin end-if if #col = 0 move #_current-column to #col end-if encode '<27>' into $escape alter-printer pitch=12 let $pos = '&a' || edit( #lin * 120 + 40 , '88888' ) || 'v' || edit( #col * 72 + 288 , '88888' ) || 'H' print-direct printer=hp $escape $pos $str alter-printer pitch=10 let #pos = ceil( #col + length( $str ) * 10.0 / 12.0 ) position (#lin,#pos) end-procedure ! hp_subscript #endif def_hp_subscript #endif inc_hp_subscript !------------------------------------------------------- hp_style_upright #ifdef inc_hp_style_upright #ifndef def_hp_style_upright #define def_hp_style_upright begin-procedure hp_style_upright !++ ! ! hp_style_upright ! ! sets the primary font style to upright ! !-- print-direct nolf printer=hp $hp_style_upright end-procedure ! hp_style_upright #endif def_hp_style_upright #endif inc_hp_style_upright !-------------------------------------------------------- hp_style_italic #ifdef inc_hp_style_italic #ifndef def_hp_style_italic #define def_hp_style_italic begin-procedure hp_style_italic !++ ! ! hp_style_italic ! ! sets the primary font style to italic ! !-- print-direct nolf printer=hp $hp_style_italic end-procedure ! hp_style_italic #endif def_hp_style_italic #endif inc_hp_style_italic !----------------------------------------------------- hp_style_condensed #ifdef inc_hp_style_condensed #ifndef def_hp_style_condensed #define def_hp_style_condensed begin-procedure hp_style_condensed !++ ! ! hp_style_condensed ! ! sets the primary font style to condensed ! !-- print-direct nolf printer=hp $hp_style_condensed end-procedure ! hp_style_condensed #endif def_hp_style_condensed #endif inc_hp_style_condensed !---------------------------------------------- hp_style_condensed_italic #ifdef inc_hp_style_condensed_italic #ifndef def_hp_style_condensed_italic #define def_hp_style_condensed_italic begin-procedure hp_style_condensed_italic !++ ! ! hp_style_condensed_italic ! ! sets the primary font style to condensed_italic ! !-- print-direct nolf printer=hp $hp_style_condensed_italic end-procedure ! hp_style_condensed_italic #endif def_hp_style_condensed_italic #endif inc_hp_style_condensed_italic !---------------------------------------------------- hp_style_compressed #ifdef inc_hp_style_compressed #ifndef def_hp_style_compressed #define def_hp_style_compressed begin-procedure hp_style_compressed !++ ! ! hp_style_compressed ! ! sets the primary font style to compressed ! !-- print-direct nolf printer=hp $hp_style_compressed end-procedure ! hp_style_compressed #endif def_hp_style_compressed #endif inc_hp_style_compressed !------------------------------------------------------ hp_style_expanded #ifdef inc_hp_style_expanded #ifndef def_hp_style_expanded #define def_hp_style_expanded begin-procedure hp_style_expanded !++ ! ! hp_style_expanded ! ! sets the primary font style to expanded ! !-- print-direct nolf printer=hp $hp_style_expanded end-procedure ! hp_style_expanded #endif def_hp_style_expanded #endif inc_hp_style_expanded !------------------------------------------------------- hp_style_outline #ifdef inc_hp_style_outline #ifndef def_hp_style_outline #define def_hp_style_outline begin-procedure hp_style_outline !++ ! ! hp_style_outline ! ! sets the primary font style to outline ! !-- print-direct nolf printer=hp $hp_style_outline end-procedure ! hp_style_outline #endif def_hp_style_outline #endif inc_hp_style_outline !-------------------------------------------------------- hp_style_inline #ifdef inc_hp_style_inline #ifndef def_hp_style_inline #define def_hp_style_inline begin-procedure hp_style_inline !++ ! ! hp_style_inline ! ! sets the primary font style to inline ! !-- print-direct nolf printer=hp $hp_style_inline end-procedure ! hp_style_inline #endif def_hp_style_inline #endif inc_hp_style_inline !------------------------------------------------------ hp_style_shadowed #ifdef inc_hp_style_shadowed #ifndef def_hp_style_shadowed #define def_hp_style_shadowed begin-procedure hp_style_shadowed !++ ! ! hp_style_shadowed ! ! sets the primary font style to shadowed ! !-- print-direct nolf printer=hp $hp_style_shadowed end-procedure ! hp_style_shadowed #endif def_hp_style_shadowed #endif inc_hp_style_shadowed !---------------------------------------------- hp_style_outline_shadowed #ifdef inc_hp_style_outline_shadowed #ifndef def_hp_style_outline_shadowed #define def_hp_style_outline_shadowed begin-procedure hp_style_outline_shadowed !++ ! ! hp_style_outline_shadowed ! ! sets the primary font style to outline_shadowed ! !-- print-direct nolf printer=hp $hp_style_outline_shadowed end-procedure ! hp_style_outline_shadowed #endif def_hp_style_outline_shadowed #endif inc_hp_style_outline_shadowed !--------------------------------------------------- hp_weight_ultra_thin #ifdef inc_hp_weight_ultra_thin #ifndef def_hp_weight_ultra_thin #define def_hp_weight_ultra_thin begin-procedure hp_weight_ultra_thin !++ ! ! hp_weight_ultra_thin ! ! sets the primary font weight to ultra_thin ! !-- print-direct nolf printer=hp $hp_weight_ultra_thin end-procedure ! hp_weight_ultra_thin #endif def_hp_weight_ultra_thin #endif inc_hp_weight_ultra_thin !--------------------------------------------------- hp_weight_extra_thin #ifdef inc_hp_weight_extra_thin #ifndef def_hp_weight_extra_thin #define def_hp_weight_extra_thin begin-procedure hp_weight_extra_thin !++ ! ! hp_weight_extra_thin ! ! sets the primary font weight to extra_thin ! !-- print-direct nolf printer=hp $hp_weight_extra_thin end-procedure ! hp_weight_extra_thin #endif def_hp_weight_extra_thin #endif inc_hp_weight_extra_thin !--------------------------------------------------------- hp_weight_thin #ifdef inc_hp_weight_thin #ifndef def_hp_weight_thin #define def_hp_weight_thin begin-procedure hp_weight_thin !++ ! ! hp_weight_thin ! ! sets the primary font weight to thin ! !-- print-direct nolf printer=hp $hp_weight_thin end-procedure ! hp_weight_thin #endif def_hp_weight_thin #endif inc_hp_weight_thin !-------------------------------------------------- hp_weight_extra_light #ifdef inc_hp_weight_extra_light #ifndef def_hp_weight_extra_light #define def_hp_weight_extra_light begin-procedure hp_weight_extra_light !++ ! ! hp_weight_extra_light ! ! sets the primary font weight to extra_light ! !-- print-direct nolf printer=hp $hp_weight_extra_light end-procedure ! hp_weight_extra_light #endif def_hp_weight_extra_light #endif inc_hp_weight_extra_light !-------------------------------------------------------- hp_weight_light #ifdef inc_hp_weight_light #ifndef def_hp_weight_light #define def_hp_weight_light begin-procedure hp_weight_light !++ ! ! hp_weight_light ! ! sets the primary font weight to light ! !-- print-direct nolf printer=hp $hp_weight_light end-procedure ! hp_weight_light #endif def_hp_weight_light #endif inc_hp_weight_light !--------------------------------------------------- hp_weight_demi_light #ifdef inc_hp_weight_demi_light #ifndef def_hp_weight_demi_light #define def_hp_weight_demi_light begin-procedure hp_weight_demi_light !++ ! ! hp_weight_demi_light ! ! sets the primary font weight to demi_light ! !-- print-direct nolf printer=hp $hp_weight_demi_light end-procedure ! hp_weight_demi_light #endif def_hp_weight_demi_light #endif inc_hp_weight_demi_light !--------------------------------------------------- hp_weight_semi_light #ifdef inc_hp_weight_semi_light #ifndef def_hp_weight_semi_light #define def_hp_weight_semi_light begin-procedure hp_weight_semi_light !++ ! ! hp_weight_semi_light ! ! sets the primary font weight to semi_light ! !-- print-direct nolf printer=hp $hp_weight_semi_light end-procedure ! hp_weight_semi_light #endif def_hp_weight_semi_light #endif inc_hp_weight_semi_light !------------------------------------------------------- hp_weight_medium #ifdef inc_hp_weight_medium #ifndef def_hp_weight_medium #define def_hp_weight_medium begin-procedure hp_weight_medium !++ ! ! hp_weight_medium ! ! sets the primary font weight to medium ! !-- print-direct nolf printer=hp $hp_weight_medium end-procedure ! hp_weight_medium #endif def_hp_weight_medium #endif inc_hp_weight_medium !---------------------------------------------------- hp_weight_semi_bold #ifdef inc_hp_weight_semi_bold #ifndef def_hp_weight_semi_bold #define def_hp_weight_semi_bold begin-procedure hp_weight_semi_bold !++ ! ! hp_weight_semi_bold ! ! sets the primary font weight to semi_bold ! !-- print-direct nolf printer=hp $hp_weight_semi_bold end-procedure ! hp_weight_semi_bold #endif def_hp_weight_semi_bold #endif inc_hp_weight_semi_bold !---------------------------------------------------- hp_weight_demi_bold #ifdef inc_hp_weight_demi_bold #ifndef def_hp_weight_demi_bold #define def_hp_weight_demi_bold begin-procedure hp_weight_demi_bold !++ ! ! hp_weight_demi_bold ! ! sets the primary font weight to demi_bold ! !-- print-direct nolf printer=hp $hp_weight_demi_bold end-procedure ! hp_weight_demi_bold #endif def_hp_weight_demi_bold #endif inc_hp_weight_demi_bold !--------------------------------------------------------- hp_weight_bold #ifdef inc_hp_weight_bold #ifndef def_hp_weight_bold #define def_hp_weight_bold begin-procedure hp_weight_bold !++ ! ! hp_weight_bold ! ! sets the primary font weight to bold ! !-- print-direct nolf printer=hp $hp_weight_bold end-procedure ! hp_weight_bold #endif def_hp_weight_bold #endif inc_hp_weight_bold !--------------------------------------------------- hp_weight_extra_bold #ifdef inc_hp_weight_extra_bold #ifndef def_hp_weight_extra_bold #define def_hp_weight_extra_bold begin-procedure hp_weight_extra_bold !++ ! ! hp_weight_extra_bold ! ! sets the primary font weight to extra_bold ! !-- print-direct nolf printer=hp $hp_weight_extra_bold end-procedure ! hp_weight_extra_bold #endif def_hp_weight_extra_bold #endif inc_hp_weight_extra_bold !-------------------------------------------------------- hp_weight_black #ifdef inc_hp_weight_black #ifndef def_hp_weight_black #define def_hp_weight_black begin-procedure hp_weight_black !++ ! ! hp_weight_black ! ! sets the primary font weight to black ! !-- print-direct nolf printer=hp $hp_weight_black end-procedure ! hp_weight_black #endif def_hp_weight_black #endif inc_hp_weight_black !-------------------------------------------------- hp_weight_extra_black #ifdef inc_hp_weight_extra_black #ifndef def_hp_weight_extra_black #define def_hp_weight_extra_black begin-procedure hp_weight_extra_black !++ ! ! hp_weight_extra_black ! ! sets the primary font weight to extra_black ! !-- print-direct nolf printer=hp $hp_weight_extra_black end-procedure ! hp_weight_extra_black #endif def_hp_weight_extra_black #endif inc_hp_weight_extra_black !-------------------------------------------------- hp_weight_ultra_black #ifdef inc_hp_weight_ultra_black #ifndef def_hp_weight_ultra_black #define def_hp_weight_ultra_black begin-procedure hp_weight_ultra_black !++ ! ! hp_weight_ultra_black ! ! sets the primary font weight to ultra_black ! !-- print-direct nolf printer=hp $hp_weight_ultra_black end-procedure ! hp_weight_ultra_black #endif def_hp_weight_ultra_black #endif inc_hp_weight_ultra_black !------------------------------------------------------- hp_font_truncate #ifdef inc_hp_font_truncate #ifndef def_hp_font_truncate #define def_hp_font_truncate begin-procedure hp_font_truncate( #font , $line , #width , :$result ) !++ ! ! hp_font_truncate( #font , $line , #width , :$result ) ! ! using font number #font, truncate the string $line to a ! printable width of #width (in points), and return the ! possibly truncated string in $result. In other words, ! $result is the longest leading string from $line that ! will fit in the printable width using the font. ! ! Note: this routine assumes that the string contains only printable ! characters; there should not be any unprintable characters, newlines, ! backspaces, tabs, carriage returns, etc.; these characters are ignored ! if encountered. ! !-- move 0 to #wid let #length = length( $line ) move 0 to #i while #i < #length and #wid < #width add 1 to #i let #c = ascii( substr( $line , #i , 1 ) ) get #w from hp_fonts( #font ) width( #c ) add #w to #wid end-while if #wid > #width subtract 1 from #i subtract #w from #wid end-if #debug show #wid ' ' #width let $result = substr( $line , 1 , #i ) end-procedure ! hp_font_truncate #endif def_hp_font_truncate #endif inc_hp_font_truncate !----------------------------------------------------------- hp_font_load #ifdef inc_hp_font_load #ifndef def_hp_font_load #define def_hp_font_load begin-procedure hp_font_load( #font , $filename , :#status ) !++ ! ! hp_font_load( #font , $filename , :#status ) ! ! Loads font #font from file $filename. If successful, #status is ! zero. If unsuccessful, #status is non-zero. ! !-- #ifndef HP_FONT_LOAD_FILE_NUM #define HP_FONT_LOAD_FILE_NUM 12345 #endif #ifndef HP_FONT_LOAD_FILE_MAX #define HP_FONT_LOAD_FILE_MAX 255 #endif open $filename as {HP_FONT_LOAD_FILE_NUM} for-reading record={HP_FONT_LOAD_FILE_MAX}:vary status=#status if not #status ! ! initialize the array ! put $filename into hp_fonts( #font ) filename move 0 to #i while #i < 256 put 0 into hp_fonts( #font ) width( #i ) add 1 to #i end-while ! ! read the file ! while 1 read {HP_FONT_LOAD_FILE_NUM} into $line:{HP_FONT_LOAD_FILE_MAX} if #_end-file break end-if let $line = ltrim( $line , ' ' ) if substr( $line , 1 , 1 ) <> '!!' unstring $line by ' ' into $p0 let $line = ltrim( substr( $line , length( $p0 ) + 1 , length( $line ) - length( $p0 ) ) , ' ' ) unstring $line by ' ' into $p1 let #c = to_number( $p0 ) let #w = to_number( $p1 ) put #w into hp_fonts( #font ) width( #c ) end-if end-while close {HP_FONT_LOAD_FILE_NUM} ! ! calculate the actual width of the character ! the input file is in millimeters for 72 characters ! we convert to points. ! move 0 to #i while #i < 256 get #w from hp_fonts( #font ) width( #i ) let #w = ( ( #w * 72.27 ) / 25.4 ) / 72.0 put #w into hp_fonts( #font ) width( #i ) add 1 to #i end-while #debug move 0 to #i #debug while #i < 256 #debug get #w from hp_fonts( #font ) width( #i ) #debug if #w > 0 #debug let $c = chr( #i ) #debug show #i edit 999 $c #w edit 999.999999 #debug end-if #debug add 1 to #i #debug end-while end-if end-procedure ! hp_font_load #endif def_hp_font_load #endif inc_hp_font_load