/* fonts.psw Support functions to determine the installed fonts. Copyright (C) 1996 Free Software Foundation, Inc. Author: Ovidiu Predescu Date: February 1997 This file is part of the GNUstep GUI X/DPS Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * PSWShowSampleString added by Masatake YAMATO. * This functions for fontpanel widget of gtkDPS. */ #include /* PSWFontNames() puts on the PS stack a sequence of two elements pairs and returns the number of the total elements. Each pair of elements consists from the name of the font and either the filename where the font is defined or the name of the font whose alias is. To get each pair of elements call the PSWGetNextFont() function. Note: This procedure depends on DGS. The function to be used on a DPS system conforming to red book should use the following statements to find out the font names: /fonts [ (%font%*) {100 string copy} 100 string filenameforall ] def The mapping between font names and file name is DPS dependent. On NeXTSTEP for example (and on systems conforming to red book), you can find out the filename where a font is defined like below: /Font /Category findresource begin /Times-Roman 1024 string ResourceFileName end This pushes on the stack %font%Times-Roman. The program should search in the standard places a directory called `Times-Roman.font' to determine the definition of the font. Maybe we should place in Postscript all the DPS dependencies and present to the program the same interface. */ defineps PSWFontNames (DPSContext ctxt| int* noOfFonts) mark /temp 1024 string def userdict /Fontmap get { /filename exch % In 3.53 the filename was passed as name; in 4.03 it is passed % as an array that contains the file name dup type /arraytype eq {aload pop} if temp cvs dup length string copy def /fontname exch temp cvs dup length string copy def fontname filename } forall counttomark 2 idiv noOfFonts endps defineps PSWGetFontsArray (DPSContext ctxt| char *fontname, *fileOrFont) fileOrFont fontname endps /* PSWCompleteFilename() returns the complete path to the filename passed as argument. The file is searched in the standard DGS places. */ defineps PSWCompleteFilename (DPSContext ctxt; char* filename; | boolean *found; char* completePath) (filename) findlibfile {closefile completePath true found} {false found pop} ifelse endps defineps PSWGetFontAndType (DPSContext ctxt | char* fontname; int* fonttype) fontname fonttype endps /* Set the current font */ defineps PSWSetFont (DPSContext ctxt; char* font; float fontMatrix[6]) (font) findfont fontMatrix makefont setfont endps /* Get the font type */ defineps PSWGetFontType (DPSContext ctxt; char* font; | int* fontType) (font) findfont /FontType get fontType endps /* Draw sample string */ defineps PSWShowSampleString(DPSContext ctxt; char * font; int size; char * sample) gsave erasepage 0 0 0 setrgbcolor /font findfont size scalefont setfont 0 %x currentfont /FontBBox get 1 get size mul 1000.0 div abs %y moveto (sample) show grestore endps /* Draw sample string safely*/ defineps PSWShowSampleSafely(DPSContext ctxt; char * font; int size; char * sample; |int * err_count) gsave % (### SampleSafely start ---------------------\n) print % pstack mark erasepage 0 0 0 setrgbcolor {/font findfont} stopped { $error /errorname get 100 string cvs (Cannot_load_font ) /Courier findfont 12 scalefont setfont }{ {size scalefont setfont currentfont /FontBBox get} stopped { % -dict- /FontBBox $error /errorname get 100 string cvs exch pop % pop unused "/FontBBox" literal exch pop % pop unused fontdict (No_FontBBox ) 0 0 }{ 1 get size mul 1000.0 div abs 0 exch % [y x] to [x y] } ifelse moveto {(sample) show} stopped { $error /errorname get 100 string cvs {counttomark} stopped { mark exch % against BUG of JIS CID vs SBC (stack_destroyed_due_to_CID_error) }{ pop } ifelse (Invalid_string ) } if } ifelse % (### SampleSafely end -----------------------\n) print % pstack counttomark err_count counttomark 1 add -1 roll pop % pop [mark] % (### SampleSafely exit ----------------------\n) print % pstack % (### ----------------------------------------\n) print grestore endps /* get strlen on Top of Stack */ defineps PSWStrLenTopOfStack(DPSContext ctxt; |int * len) dup length len endps /* get string on Top of Stack, for UNLIMITED buffer */ defineps PSWStrCpyTopOfStack(DPSContext ctxt; |char * str) str endps /* get string on Top of Stack, for LIMITED buffer */ defineps PSWStrNCpyTopOfStack(DPSContext ctxt; int len; |char * str) dup length len gt { 0 len getinterval } if str endps