Consultor Eletrônico



Kbase 19056: _osprint: How to Dynamically Change Font to Fit Content in Frame
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   15/10/2008
Status: Verified

GOAL:

_osprint: How to Dynamically Change Font to Fit Content in Frame

FACT(s) (Environment):

Progress 8.X
Progress 9.X
_osprint

CAUSE:

Developers can use the _osprint.p program to dynamically choose a smaller or larger font, thereby adjusting the contents for a better fit within the containing frame.

FIX:

/**************************************************************/
/************* Dynamic Font Change Demo ****************/
/*The following Procedure uses attributes of the FONT-TABLE to*/
/*Dynamically change the Font size of the output dependent on */
/*the width of the output. This Procedure takes advantage of */
/*using Proportional Fonts and Progress' _osprint.p Procedure */
/*to apply those fonts prior to sending output to a Printer. */
/**************************************************************/
/**************************************************************/

DEFINE VARIABLE x AS CHARACTER NO-UNDO.
DEFINE VARIABLE y AS CHARACTER NO-UNDO.
DEFINE VARIABLE logVar AS LOG NO-UNDO.
DEFINE VARIABLE fnt AS INTEGER NO-UNDO.

ASSIGN x =
"SDA SDF DFDS LKJLKJLKJ LKJ565SDA SDF DFDS SD F SDF SD SDF " +
"SDF DSF SDF S FSA SDGF FDS SDAF SADF SDF SDF SDF SDF DF"
y = "DSFSDAF FDSFDSA F FSADF SDF F SFD SDF SFD SDF " +
"SDF SFD SDF SDF SDF FDS SDF S DF S DF DSAF SDAF SDF SFD " +
"SDF SDF SDF FD".

/***************************************************************/
/***************************************************************/
/*For this test I set up Fonts 10 through 16 with the following*/
/* Proportional fonts: */
/* Font10=Small Fonts,Size=2 */
/* Font11=Small Fonts,Size=3 */
/* Font12=Small Fonts,Size=4 */
/* Font13=Small Fonts,Size=5 */
/* Font14=Small Fonts,Size=6 */
/* Font15=Small Fonts,Size=7 */
/* Font16=MS Sans Serif,Size=8 */
/*To Access these font, you will need to set them up in your */
/*Registry or Progress .INI file prior to running this program.*/
/***************************************************************/
/***************************************************************/

/***************************************************************/
/***************************************************************/
/*In the following Section, we test the Width in Characters of */
/*Output against the Font Size using the GET-TEXT-WIDTH-CHARS */
/*method of the FONT-TABLE and checking that the total Output */
/*Width in Characters is less than 255, which is the maximum */
/*number of Characters per Line that _osprint.p can output. */
/***************************************************************/
/***************************************************************/

IF FONT-TABLE:GET-TEXT-WIDTH-CHARS(x, 16) +
FONT-TABLE:GET-TEXT-WIDTH-CHARS(y, 16) < 255 THEN
ASSIGN fnt = 16.
ELSE IF FONT-TABLE:GET-TEXT-WIDTH-CHARS(x, 15) +
FONT-TABLE:GET-TEXT-WIDTH-CHARS(y, 16) < 255 THEN
ASSIGN fnt = 15.
ELSE IF FONT-TABLE:GET-TEXT-WIDTH-CHARS(x, 14) +
FONT-TABLE:GET-TEXT-WIDTH-CHARS(y, 16) < 255 THEN
ASSIGN fnt = 14.
ELSE IF FONT-TABLE:GET-TEXT-WIDTH-CHARS(x, 13) +
FONT-TABLE:GET-TEXT-WIDTH-CHARS(y, 16) < 255 THEN
ASSIGN fnt = 13.
ELSE IF FONT-TABLE:GET-TEXT-WIDTH-CHARS(x, 12) +
FONT-TABLE:GET-TEXT-WIDTH-CHARS(y, 16) < 255 THEN
ASSIGN fnt = 12.
ELSE IF FONT-TABLE:GET-TEXT-WIDTH-CHARS(x, 11) +
FONT-TABLE:GET-TEXT-WIDTH-CHARS(y, 16) < 255 THEN
ASSIGN fnt = 11.
ELSE IF FONT-TABLE:GET-TEXT-WIDTH-CHARS(x, 10) +
FONT-TABLE:GET-TEXT-WIDTH-CHARS(y, 16) < 255 THEN
ASSIGN fnt = 10.


OUTPUT TO FontTest.txt PAGED.
PUT UNFORMATTED x y.
OUTPUT CLOSE.


/***************************************************************/
/*In the following section, _osprint.p is being called to print*/
/*the output file. The Parameters are described as follows: */
/* RUN adecomm/_osprint.p */
/* (INPUT ParentWindow(HANDLE) "This Passes the WIDGET-HANDLE*/
/* of the Window that you want to parent. any dialog boxes, ie..*/
/* Printer Setup, Printer Status, etc... (? for default or */
/* CURRENT-WINDOW." */
/* INPUT PrintFile(CHARACTER) "This passes the name of the */
/* file to print. You can specify absolute or Relative path */
/* for the file, _osprint.p searches the PROPATH to locate */
/* the file." */
/* INPUT FontNumber(INTEGER) "This passes the Font Number that */
/* you want to use for your output". */
/* INPUT UseDialog(INTEGER) "Determine whether you want */
/* _osprint.p to display the PRINTER-SETUP Dialog Box and or */
/* to pass options to the printer. This example uses 2 which */
/* tells _osprint.p NOT to display the Dialog, but to print in */
/* Landscape Mode. (For more options see the Programming */
/* Handbook)." */
/* INPUT PageSize(INTEGER) "Represents the maximum number of */
/* Lines per Page, 0 lets the Printer decide." */
/* INPUT PageCount(INTEGER) "Limits number of pages that are */
/* Printed, 0 means Print All." */
/* OUTPUT Result(LOGICAL) "Reports Success or Failure of the */
/* Print Request." */
/***************************************************************/
/***************************************************************/

RUN adecomm/_osprint.p (INPUT ? , INPUT "FontTest.txt" ,
INPUT fnt , INPUT 2 , INPUT 0,
INPUT 0 , OUTPUT logVar) .

CASE logVar:
WHEN TRUE THEN
MESSAGE "Print Job Successful!!!" VIEW-AS ALERT-BOX.
WHEN FALSE THEN
MESSAGE "Print Job Unsuccessful!!!" VIEW-AS ALERT-BOX.
END CASE..