Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / font.h
1 /*****************************************************************************\
2   font.h : Interface for the font classes
3
4   Copyright (c) 1996 - 2001, Hewlett-Packard Co.
5   All rights reserved.
6
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
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.
18
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 \*****************************************************************************/
30
31
32 #ifndef APDK_FONT_H
33 #define APDK_FONT_H
34 #if defined(APDK_FONTS_NEEDED)
35
36 APDK_BEGIN_NAMESPACE
37
38 // font names
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";
44 \r
45 class PrintContext;\r
46
47 //Font
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.)
53
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.
57 Example:
58          Font* myFont = myJob->RealizeFont(FIXED_SERIF,12,...);
59
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
64 instances to client.
65
66 \sa ReferenceFont
67 ******************************************************************************/
68 class Font
69 {
70 friend class Printer;
71 friend class TextManager;
72 public:
73
74     // constructors are protected -- clients use Job::RealizeFont()
75     virtual ~Font();
76
77     // public functions
78
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);
82
83 ////// these functions allow access to properties of derived classes
84
85     //! Returns the typeface name.
86     virtual const char* GetName() const { return sBad; }
87
88     //! Tells whether text bolding is available.
89     virtual BOOL IsBoldAllowed() const { return FALSE; }
90
91     //! Tells whether text italicizing is available.
92     virtual BOOL IsItalicAllowed() const { return FALSE; }
93
94     //! Tells whether text underlining is available.
95     virtual BOOL IsUnderlineAllowed() const { return FALSE; }
96
97     //! Tells whether text coloring is available.
98     virtual BOOL IsColorAllowed() const { return FALSE; }
99
100     //! Tells whether this font is proportionally spaced, as opposed to fixed.
101     virtual BOOL IsProportional() const { return FALSE; }
102
103     //! Tells whether this typeface has serifs.
104     virtual BOOL HasSerif() const { return FALSE; }
105
106
107     /*!
108     For fixed fonts, returns the pitch for given point-size.
109     (Returns zero for proportional fonts.)
110     */
111     virtual BYTE GetPitch(const BYTE pointsize) const
112         { return 0; }   // default for proportionals
113
114 ////// these data members give the properties of the actual instance
115     // as set by the user
116     BYTE        iPointsize;
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
121     int         iPitch;
122
123     // string designating character set (as recognized by firmware)
124     //
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];
129
130     BOOL PrinterBased;
131
132     //! Index of point-size from available list for this font.
133     virtual int Index() { return -1; };
134
135     // items for spooling
136 //  virtual BOOL Equal(Font* f);
137 //  virtual DRIVER_ERROR Store(FILE* sp, int& size);
138 //  virtual int SpoolSize();
139 #ifdef APDK_CAPTURE
140     SystemServices* pSS;
141     void Capture_dFont(const unsigned int ptr);
142 #endif
143 protected:
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);
149
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);
154
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;
158
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
164         { return 0; }
165
166     // match arbitrary input size to one we have
167     BYTE AssignSize(BYTE Size);
168     void Subst_Char(int& bCurrChar)const;
169
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];
174
175     unsigned int PrinterVRes;
176     unsigned int PrinterHRes;
177
178     BOOL internal;  // true iff font belongs to printer
179
180 }; //Font
181
182 //ReferenceFont
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
188 cannot be deleted.
189
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.
193
194 \sa Font Printer
195 ******************************************************************************/
196 class ReferenceFont : public Font
197 {
198 friend class Printer;           // deletes from its fontarray
199 friend class DJ400;        // replaces fontarray from base class
200 public:
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);
205 protected:
206     ~ReferenceFont();
207
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);
212
213 }; //ReferenceFont
214
215
216 #ifdef APDK_COURIER
217 // fixed-pitch, serif
218
219 extern BYTE CourierSizes[];
220
221 class Courier : public ReferenceFont
222 {
223 friend class Printer;
224 public:
225     Courier(BYTE size=0,
226             BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
227             TEXTCOLOR=BLACK_TEXT, unsigned int SizesAvailable=3);
228     virtual ~Courier();
229
230
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; }
239
240     int Index() { return COURIER_INDEX; }
241
242     BYTE unused;    // left for future use by clients
243
244 protected:
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);
254         return c;
255      }
256 }; //Courier
257
258 #ifdef APDK_DJ400
259
260 extern BYTE Courier400Sizes[];
261
262 class Courier400 : public Courier
263 {
264 friend class DJ400;
265 public:
266     Courier400(BYTE size=0,
267             BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE);
268
269     BOOL IsColorAllowed() const { return FALSE; }
270
271
272 protected:
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);
281         return c;
282      }
283 }; //Courier400
284
285 #endif // APDK_DJ400
286
287 #endif // APDK_COURIER
288
289
290 #ifdef APDK_CGTIMES
291 // proportional, serif
292
293 extern BYTE CGTimesSizes[];
294
295 class CGTimes : public ReferenceFont
296 {
297 friend class Printer;
298 public:
299     CGTimes(BYTE size=0,
300             BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
301             TEXTCOLOR=BLACK_TEXT, unsigned int SizesAvailable=5);
302
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; }
310
311     int Index() { return CGTIMES_INDEX; }
312
313 protected:
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);
323         return c;
324      }
325 }; //CGTimes
326
327
328 #ifdef APDK_DJ400
329
330 extern BYTE CGTimes400Sizes[];
331
332 class CGTimes400 : public CGTimes
333 {
334 friend class DJ400;
335 public:
336     CGTimes400(BYTE size=0,
337             BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE);
338
339     BOOL IsColorAllowed() const { return FALSE; }
340
341
342 protected:
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);
352         return c;
353      }
354 }; //CGTimes400
355
356
357 #endif  // ifdef APDK_DJ400
358
359 #endif  // ifdef APDK_CGTIMES
360
361
362 #ifdef APDK_LTRGOTHIC
363 // fixed-pitch, sans-serif
364
365 extern BYTE LetterGothicSizes[];
366
367
368 class LetterGothic : public ReferenceFont
369 {
370 friend class Printer;
371 public:
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();
376
377
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; }
386
387     int Index() { return LETTERGOTHIC_INDEX; }
388
389     BYTE unused;    // left for future use by clients
390
391 protected:
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);
401         return c;
402      }
403 }; //LettrerGothic
404
405 #ifdef APDK_DJ400
406
407 extern BYTE LetterGothic400Sizes[];
408
409 class LetterGothic400 : public LetterGothic
410 {
411 friend class DJ400;
412 public:
413     LetterGothic400(BYTE size=0,
414             BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE);
415
416     BOOL IsColorAllowed() const { return FALSE; }
417
418
419 protected:
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);
428         return c;
429      }
430 }; //LetterGothic400
431
432 #endif // APDK_DJ400
433
434 #endif  // APDK_LTRGOTHIC
435
436
437 #ifdef APDK_UNIVERS
438 // proportional, sans-serif
439
440 extern BYTE UniversSizes[];
441
442 class Univers : public ReferenceFont
443 {
444 friend class Printer;
445 public:
446     Univers(BYTE size=0,
447             BOOL bold=FALSE, BOOL italic=FALSE, BOOL underline=FALSE,
448             TEXTCOLOR=BLACK_TEXT, unsigned int SizesAvailable=3);
449
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; }
457
458     int Index() { return UNIVERS_INDEX; }
459
460 protected:
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);
470         return c;
471      }
472 }; //Univers
473
474 #endif  // APDK_UNIVERS
475
476 APDK_END_NAMESPACE
477
478 #endif  //APDK_FONTS_NEEDED
479 #endif  //APDK_FONT_H
480