1 /*****************************************************************************\
2 font.h : Interface for the font classes
4 Copyright (c) 1996 - 2001, Hewlett-Packard Co.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3. Neither the name of Hewlett-Packard nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \*****************************************************************************/
34 #if defined(APDK_FONTS_NEEDED)
39 const char sCourier[]="Courier";
40 const char sCGTimes[]="CGTimes";
41 const char sLetterGothic[]="LetterGothic";
42 const char sUnivers[]="Univers";
43 const char sBad[]="Bad";
48 //! Base class for font support
49 /*! \class Font font.h "hpprintapi.h"
50 This object is used to control printer fonts when sending ASCII data.
51 (For systems that lack a reasonable font engine or for some reason can
52 benefit from using printer fonts.)
54 It is not abstract, so that clients can request a font generically,
55 but its constructor is not public -- Fonts are rather created
56 through RealizeFont -- thus it is effectively "abstract" in this sense.
58 Font* myFont = myJob->RealizeFont(FIXED_SERIF,12,...);
60 Note that Printer initially constructs a dummy font (with default values)
61 for each of its typefaces, so that the Is<x>Allowed functions can be
62 invoked (for EnumFonts) prior to choosing specific instances.
63 Then the Clone function is invoked by Printer::RealizeFont to provide
67 ******************************************************************************/
71 friend class TextManager;
74 // constructors are protected -- clients use Job::RealizeFont()
79 // the base class version is really for printer fonts
80 virtual DRIVER_ERROR GetTextExtent(PrintContext* pPC, const char* pTextString,const int iLenString,
81 int& iHeight, int& iWidth);
83 ////// these functions allow access to properties of derived classes
85 //! Returns the typeface name.
86 virtual const char* GetName() const { return sBad; }
88 //! Tells whether text bolding is available.
89 virtual BOOL IsBoldAllowed() const { return FALSE; }
91 //! Tells whether text italicizing is available.
92 virtual BOOL IsItalicAllowed() const { return FALSE; }
94 //! Tells whether text underlining is available.
95 virtual BOOL IsUnderlineAllowed() const { return FALSE; }
97 //! Tells whether text coloring is available.
98 virtual BOOL IsColorAllowed() const { return FALSE; }
100 //! Tells whether this font is proportionally spaced, as opposed to fixed.
101 virtual BOOL IsProportional() const { return FALSE; }
103 //! Tells whether this typeface has serifs.
104 virtual BOOL HasSerif() const { return FALSE; }
108 For fixed fonts, returns the pitch for given point-size.
109 (Returns zero for proportional fonts.)
111 virtual BYTE GetPitch(const BYTE pointsize) const
112 { return 0; } // default for proportionals
114 ////// these data members give the properties of the actual instance
115 // as set by the user
117 BOOL bBold; // boolean TRUE to request bold
118 BOOL bItalic; // boolean TRUE to request italic
119 BOOL bUnderline; // boolean TRUE to request underline
120 TEXTCOLOR eColor; // enum
123 // string designating character set (as recognized by firmware)
125 //!\todo is this comment still valid?
126 // REVISIT: shouldn't really have Translator data here; we
127 // should have an enum here, which is interpreted by Translator
128 char charset[MAX_CHAR_SET];
132 //! Index of point-size from available list for this font.
133 virtual int Index() { return -1; };
135 // items for spooling
136 // virtual BOOL Equal(Font* f);
137 // virtual DRIVER_ERROR Store(FILE* sp, int& size);
138 // virtual int SpoolSize();
141 void Capture_dFont(const unsigned int ptr);
144 // constructor, invoked by derivative constructors
145 Font(int SizesAvailable,BYTE size=0,
146 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
147 TEXTCOLOR color=BLACK_TEXT,BOOL printer=TRUE,
148 unsigned int pvres=300,unsigned int phres=300);
150 // copy constructor used by RealizeFont
151 Font(const Font& f,const BYTE bSize,
152 const TEXTCOLOR color, const BOOL bold,
153 const BOOL italic, const BOOL underline);
155 // return a clone with a different character set
156 // base class version should not be called -- this should be pure virtual!
157 virtual Font* CharSetClone(char* NewCharSet) const;
159 int numsizes; // number of available pointsizes
160 // return array of sizes allowed
161 virtual BYTE* GetSizes() const { return (BYTE*)NULL; }
162 // return index of pointsize from array of available pointsizes
163 virtual int Ordinal(unsigned int /* pointsize */) const
166 // match arbitrary input size to one we have
167 BYTE AssignSize(BYTE Size);
168 void Subst_Char(int& bCurrChar)const;
170 // pointers to the arrays containing widths for a given font
171 // separated into Lo (32..127) & Hi (160..255)
172 const BYTE *pWidthLo[MAX_POINTSIZES];
173 const BYTE *pWidthHi[MAX_POINTSIZES];
175 unsigned int PrinterVRes;
176 unsigned int PrinterHRes;
178 BOOL internal; // true iff font belongs to printer
183 //! Used by Job to realize a font
184 /*! \class ReferenceFont font.h "hpprintapi.h"
185 Subclass ReferenceFont (EnumFont) is used to query available font properties
186 prior to instantiating the font. Whereas Font objects created upon request are
187 to be deleted by caller, ReferenceFonts live with the core structures and
190 The main purpose of this class is to hide the destructor, since
191 the fonts that live with the Printer and are returned by EnumFont
192 are meant to remain alive for the life of the Printer.
195 ******************************************************************************/
196 class ReferenceFont : public Font
198 friend class Printer; // deletes from its fontarray
199 friend class DJ400; // replaces fontarray from base class
201 ReferenceFont(int SizesAvailable,BYTE size=0,
202 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
203 TEXTCOLOR color=BLACK_TEXT,BOOL printer=TRUE,
204 unsigned int pvres=300,unsigned int phres=300);
208 // copy constructor used by RealizeFont
209 ReferenceFont(const ReferenceFont& f,const BYTE bSize,
210 const TEXTCOLOR color, const BOOL bold,
211 const BOOL italic, const BOOL underline);
217 // fixed-pitch, serif
219 extern BYTE CourierSizes[];
221 class Courier : public ReferenceFont
223 friend class Printer;
226 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
227 TEXTCOLOR=BLACK_TEXT, unsigned int SizesAvailable=3);
231 BYTE GetPitch(const BYTE pointsize)const;
232 const char* GetName() const { return sCourier; }
233 BOOL IsBoldAllowed() const { return TRUE; }
234 BOOL IsItalicAllowed() const { return TRUE; }
235 BOOL IsUnderlineAllowed() const { return TRUE; }
236 virtual BOOL IsColorAllowed() const { return TRUE; }
237 BOOL IsProportional() const { return FALSE; }
238 BOOL HasSerif() const { return TRUE; }
240 int Index() { return COURIER_INDEX; }
242 BYTE unused; // left for future use by clients
245 Courier(const Courier& f,const BYTE bSize,
246 const TEXTCOLOR color, const BOOL bold,
247 const BOOL italic, const BOOL underline);
248 int Ordinal(unsigned int pointsize)const;
249 virtual BYTE* GetSizes() const { return CourierSizes; }
250 virtual Font* CharSetClone(char* NewCharSet) const
251 { Courier* c = new Courier(*this,iPointsize,eColor,bBold,bItalic,bUnderline);
252 if (c==NULL) return (Font*)NULL;
253 strcpy(c->charset, NewCharSet);
260 extern BYTE Courier400Sizes[];
262 class Courier400 : public Courier
266 Courier400(BYTE size=0,
267 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE);
269 BOOL IsColorAllowed() const { return FALSE; }
273 Courier400(const Courier400& f,const BYTE bSize,
274 const TEXTCOLOR color, const BOOL bold,
275 const BOOL italic, const BOOL underline);
276 BYTE* GetSizes() const { return Courier400Sizes; }
277 Font* CharSetClone(char* NewCharSet) const
278 { Courier400* c = new Courier400(*this,iPointsize,eColor,bBold,bItalic,bUnderline);
279 if (c==NULL) return (Font*)NULL;
280 strcpy(c->charset, NewCharSet);
287 #endif // APDK_COURIER
291 // proportional, serif
293 extern BYTE CGTimesSizes[];
295 class CGTimes : public ReferenceFont
297 friend class Printer;
300 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
301 TEXTCOLOR=BLACK_TEXT, unsigned int SizesAvailable=5);
303 const char* GetName() const { return sCGTimes; }
304 BOOL IsBoldAllowed() const { return TRUE; }
305 BOOL IsItalicAllowed() const { return TRUE; }
306 BOOL IsUnderlineAllowed() const { return TRUE; }
307 virtual BOOL IsColorAllowed() const { return TRUE; }
308 BOOL IsProportional() const { return TRUE; }
309 BOOL HasSerif() const { return TRUE; }
311 int Index() { return CGTIMES_INDEX; }
314 CGTimes(const CGTimes& f,const BYTE bSize,
315 const TEXTCOLOR color, const BOOL bold,
316 const BOOL italic, const BOOL underline);
317 int Ordinal(unsigned int pointsize)const;
318 virtual BYTE* GetSizes() const { return CGTimesSizes; }
319 virtual Font* CharSetClone(char* NewCharSet) const
320 { CGTimes* c = new CGTimes(*this,iPointsize,eColor,bBold,bItalic,bUnderline);
321 if (c==NULL) return (Font*)NULL;
322 strcpy(c->charset, NewCharSet);
330 extern BYTE CGTimes400Sizes[];
332 class CGTimes400 : public CGTimes
336 CGTimes400(BYTE size=0,
337 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE);
339 BOOL IsColorAllowed() const { return FALSE; }
343 CGTimes400(const CGTimes400& f,const BYTE bSize,
344 const TEXTCOLOR color, const BOOL bold,
345 const BOOL italic, const BOOL underline);
346 int Ordinal(unsigned int pointsize)const;
347 BYTE* GetSizes() const { return CGTimes400Sizes; }
348 Font* CharSetClone(char* NewCharSet) const
349 { CGTimes400* c = new CGTimes400(*this,iPointsize,eColor,bBold,bItalic,bUnderline);
350 if (c==NULL) return (Font*)NULL;
351 strcpy(c->charset, NewCharSet);
357 #endif // ifdef APDK_DJ400
359 #endif // ifdef APDK_CGTIMES
362 #ifdef APDK_LTRGOTHIC
363 // fixed-pitch, sans-serif
365 extern BYTE LetterGothicSizes[];
368 class LetterGothic : public ReferenceFont
370 friend class Printer;
372 LetterGothic(BYTE size=0,
373 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
374 TEXTCOLOR=BLACK_TEXT, unsigned int SizesAvailable=3);
375 virtual ~LetterGothic();
378 BYTE GetPitch(const BYTE pointsize)const;
379 const char* GetName() const { return sLetterGothic; }
380 BOOL IsBoldAllowed() const { return TRUE; }
381 BOOL IsItalicAllowed() const { return TRUE; }
382 BOOL IsUnderlineAllowed() const { return TRUE; }
383 virtual BOOL IsColorAllowed() const { return TRUE; }
384 BOOL IsProportional() const { return FALSE; }
385 BOOL HasSerif() const { return FALSE; }
387 int Index() { return LETTERGOTHIC_INDEX; }
389 BYTE unused; // left for future use by clients
392 LetterGothic(const LetterGothic& f,const BYTE bSize,
393 const TEXTCOLOR color, const BOOL bold,
394 const BOOL italic, const BOOL underline);
395 int Ordinal(unsigned int pointsize)const;
396 virtual BYTE* GetSizes() const { return LetterGothicSizes; }
397 virtual Font* CharSetClone(char* NewCharSet) const
398 { LetterGothic* c = new LetterGothic(*this,iPointsize,eColor,bBold,bItalic,bUnderline);
399 if (c==NULL) return (Font*)NULL;
400 strcpy(c->charset, NewCharSet);
407 extern BYTE LetterGothic400Sizes[];
409 class LetterGothic400 : public LetterGothic
413 LetterGothic400(BYTE size=0,
414 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE);
416 BOOL IsColorAllowed() const { return FALSE; }
420 LetterGothic400(const LetterGothic400& f,const BYTE bSize,
421 const TEXTCOLOR color, const BOOL bold,
422 const BOOL italic, const BOOL underline);
423 BYTE* GetSizes() const { return LetterGothic400Sizes; }
424 Font* CharSetClone(char* NewCharSet) const
425 { LetterGothic400* c = new LetterGothic400(*this,iPointsize,eColor,bBold,bItalic,bUnderline);
426 if (c==NULL) return (Font*)NULL;
427 strcpy(c->charset, NewCharSet);
434 #endif // APDK_LTRGOTHIC
438 // proportional, sans-serif
440 extern BYTE UniversSizes[];
442 class Univers : public ReferenceFont
444 friend class Printer;
447 BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
448 TEXTCOLOR=BLACK_TEXT, unsigned int SizesAvailable=3);
450 const char* GetName() const { return sUnivers; }
451 BOOL IsBoldAllowed() const { return TRUE; }
452 BOOL IsItalicAllowed() const { return TRUE; }
453 BOOL IsUnderlineAllowed() const { return TRUE; }
454 virtual BOOL IsColorAllowed() const { return TRUE; }
455 BOOL IsProportional() const { return TRUE; }
456 BOOL HasSerif() const { return FALSE; }
458 int Index() { return UNIVERS_INDEX; }
461 Univers(const Univers& f,const BYTE bSize,
462 const TEXTCOLOR color, const BOOL bold,
463 const BOOL italic, const BOOL underline);
464 int Ordinal(unsigned int pointsize)const;
465 virtual BYTE* GetSizes() const { return UniversSizes; }
466 virtual Font* CharSetClone(char* NewCharSet) const
467 { Univers* c = new Univers(*this,iPointsize,eColor,bBold,bItalic,bUnderline);
468 if (c==NULL) return (Font*)NULL;
469 strcpy(c->charset, NewCharSet);
474 #endif // APDK_UNIVERS
478 #endif //APDK_FONTS_NEEDED