XamlFont.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 #if !defined XAML_FONT_HEADER
00020 #define XAML_FONT_HEADER
00021 
00025 
00026 #include "XAML/XamlCore.h"
00027 
00028 #include "whiptk/font.h"
00029 #include "XAML/XamlXML.h"
00030 
00031 
00036 
00037 
00043 class XAMLTK_API WT_XAML_Font 
00044     : public WT_Font
00045     , public XamlDrawableAttributes::FontRenderingEmSize::Provider
00046     , public XamlDrawableAttributes::FontUri::Provider
00047         , public XamlDrawableAttributes::IsSideways::Provider
00048     , public XamlDrawableAttributes::StyleSimulations::Provider
00049     , public XamlDrawableAttributes::GlyphsAttributeProvider
00050 {
00051         friend class WT_XAML_Class_Factory;
00052         friend class WT_XAML_Rendition;
00053 
00054 protected:
00056 
00057     WT_XAML_Font()
00058         : WT_Font( ) 
00059         , _pSerializeFile( NULL )
00060         {}
00061 
00063     WT_XAML_Font (
00064         WT_String             name, 
00065         WT_Boolean            bold, 
00066         WT_Boolean            italic, 
00067         WT_Boolean            underline, 
00068         WT_Byte               charset, 
00069         WT_Byte               pitch, 
00070         WT_Byte               family, 
00071         WT_Integer32          height, 
00072         WT_Unsigned_Integer16 rotation, 
00076         WT_Unsigned_Integer16 width_scale,
00081         WT_Unsigned_Integer16 spacing,
00085         WT_Unsigned_Integer16 oblique,
00086         WT_Integer32          flags = 0 
00087         )
00088                 :WT_Font(name,bold,italic,underline,charset,pitch,family,height,rotation,width_scale,spacing,oblique,flags)
00089         , _pSerializeFile( NULL )
00090         {}
00091 
00092         WT_XAML_Font(WT_Font const& font)
00093                 :WT_Font(font)
00094         {}
00095 
00096         virtual ~WT_XAML_Font()
00097         {}
00099 public:
00100 
00102     WT_XAML_Font const & operator=  (WT_XAML_Font const & font)
00103         {
00104                 WT_Font::operator = (font);
00105                 return *this;
00106         }
00107 
00109     WT_Result        serialize (WT_File & /*file*/) const;
00110 
00112         WT_Result                parseAttributeList(XamlXML::tAttributeMap& rMap, WT_XAML_File& rFile);
00113 
00114     //Font utility functions
00115     static WT_Result obfuscate(DWFInputStream* in, DWFOutputStream* out, const char* key);
00116     static WT_Result parseKey( char* keyOut, const wchar_t* zFontUriIn);
00117 
00118 protected:
00119     virtual WT_Result provideFontRenderingEmSize( XamlDrawableAttributes::FontRenderingEmSize*& );
00120     virtual WT_Result provideFontUri( XamlDrawableAttributes::FontUri*& );
00121         virtual WT_Result provideIsSideways( XamlDrawableAttributes::IsSideways*& );
00122     virtual WT_Result provideStyleSimulations( XamlDrawableAttributes::StyleSimulations*& );
00123     virtual WT_Result provideGlyphsAttributes( XamlDrawableAttributes::GlyphsAttributeConsumer* p, WT_XAML_File& r) const;
00124 
00125 private:
00126     WT_XAML_File *_pSerializeFile;
00127 
00128 public:
00129     //This is the TTF file header
00130     typedef struct _tagTT_OFFSET_TABLE{
00131         unsigned short  uMajorVersion;
00132         unsigned short  uMinorVersion;
00133         unsigned short  uNumOfTables;
00134         unsigned short  uSearchRange;
00135         unsigned short  uEntrySelector;
00136         unsigned short  uRangeShift;
00137     }TT_OFFSET_TABLE;
00138 
00139     //Tables in the TTF file and their placement and name (tag)
00140     typedef struct _tagTT_TABLE_DIRECTORY{
00141         char  szTag[4];      //table name
00142         unsigned long uCheckSum;     //Check sum
00143         unsigned long uOffset;       //Offset from beginning of file
00144         unsigned long uLength;       //length of the table in bytes
00145     }TT_TABLE_DIRECTORY;
00146 
00147     //TTF HEAD table
00148     typedef struct _tagTT_HEAD_TABLE
00149     {
00150         unsigned long nTable;               //version number 0x00010000 for version 1.0. 
00151         unsigned long nFfontRevision;        //Set by font manufacturer. 
00152         unsigned long nCheckSumAdjustment;   //To compute: set it to 0, sum the entire font as unsigned long, then store 0xB1B0AFBA - sum. 
00153         unsigned long nMagicNumber;          //Set to 0x5F0F3CF5. 
00154         unsigned short nFlags;               //Bit 0: Baseline for font at y=0;
00155         //Bit 1: Left sidebearing point at x=0;
00156         //Bit 2: Instructions may depend on point size; 
00157         //Bit 3: Force ppem to integer values for all internal scaler math; may use fractional ppem sizes if this bit is clear; 
00158         //Bit 4: Instructions may alter advance width (the advance widths might not scale linearly); 
00159         //Bits 5-10: These should be set according to Apple's specification . However, they are not implemented in OpenType. 
00160         //Bit 11: Font data is 'lossless,' as a result of having been compressed and decompressed with the Agfa MicroType Express engine.
00161         //Bit 12: Font converted (produce compatible metrics)
00162         //Bit 13: Font optimised for ClearType
00163         //Bit 14: Reserved, set to 0
00164         //Bit 15: Reserved, set to 0 
00165         unsigned short nUnitsPerEm;          //Valid range is from 16 to 16384. This value should be a power of 2 for fonts that have TrueType outlines. 
00166         long long nCreated;                  //Number of seconds since 12:00 midnight, January 1, 1904. 64-bit integer 
00167         long long nModified;                 //Number of seconds since 12:00 midnight, January 1, 1904. 64-bit integer 
00168         short nXMin;                         //For all glyph bounding boxes. 
00169         short nYMin;                         //For all glyph bounding boxes. 
00170         short nXMax;                         //For all glyph bounding boxes. 
00171         short nYMax;                         //For all glyph bounding boxes. 
00172         unsigned short nMacStyle;            //Bit 0: Bold (if set to 1); 
00173         //Bit 1: Italic (if set to 1) 
00174         //Bit 2: Underline (if set to 1) 
00175         //Bit 3: Outline (if set to 1) 
00176         //Bit 4: Shadow (if set to 1) 
00177         //Bit 5: Condensed (if set to 1) 
00178         //Bit 6: Extended (if set to 1) 
00179         //Bits 7-15: Reserved (set to 0).  
00180         unsigned short nLowestRecPPEM;       //Smallest readable size in pixels. 
00181         short nFontDirectionHint;            //0: Fully mixed directional glyphs; 
00182         //1: Only strongly left to right; 
00183         //2: Like 1 but also contains neutrals; 
00184         //-1: Only strongly right to left; 
00185         //-2: Like -1 but also contains neutrals. 1 
00186         short nIndexToLocFormat;             //0 for short offsets, 1 for long. 
00187         short nGlyphDataFormat;              //
00188     } TT_HEAD_TABLE;
00189 
00190     //Header of the horizontal header table
00191     typedef struct _tagTT_HHEA_TABLE_HEADER{
00192         unsigned long nVersion;  //Table version number
00193         short nAscender;         //Typographic ascent. (Distance from baseline of highest ascender)  
00194         short nDescender;        //Typographic descent. (Distance from baseline of lowest descender)  
00195         short nLineGap;          //Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7. 
00196         unsigned short nAdvanceWidthMax; //Maximum advance width value in 'hmtx' table. 
00197         short nMinLeftSideBearing;  //Minimum left side bearing value in 'hmtx' table. 
00198         short nMinRightSideBearing; //Minimum right side bearing value; calculated as Min(aw - lsb - (xMax - xMin)). 
00199         short nXMaxExtent;      //Max(lsb + (xMax - xMin)). 
00200         short nCaretSlopeRise;  //Used to calculate the slope of the cursor (rise/run); 1 for vertical. 
00201         short nCaretSlopeRun;   // 0 for vertical. 
00202         short nCaretOffset;     // The amount by which a slanted highlight on a glyph needs to be shifted to produce the best appearance. Set to 0 for non-slanted fonts 
00203         short nReserved0;       //(reserved) set to 0 
00204         short nReserved1;       //(reserved) set to 0 
00205         short nReserved2;       //(reserved) set to 0 
00206         short nReserved3;       //(reserved) set to 0 
00207         short nMetricDataFormat; // 0 for current format. 
00208         unsigned short nNumberOfHMetrics; //Number of hMetric entries in 'hmtx' table 
00209     } TT_HHEA_TABLE_HEADER;
00210 
00211     typedef struct _tagTT_HORZ_METRIC {
00212         unsigned short advanceWidth;
00213         short lsb;
00214     }  TT_HORZ_METRIC;
00215 
00216     typedef struct _tagTT_CMAP_TABLE_HEADER{
00217         unsigned short nVersion;
00218         unsigned short nNumTables;
00219     } TT_CMAP_TABLE_HEADER;
00220 
00221     typedef struct _tagTT_CMAP_TABLE_RECORD{
00222         unsigned short nPlatformID;
00223         unsigned short nEncodingID;
00224         unsigned long nOffset;
00225     } TT_CMAP_TABLE_RECORD;
00226 
00227     typedef struct _tagTT_CMAP_ENCODING_HEADER{
00228         unsigned short nFormat;
00229         unsigned short nLength;
00230         unsigned short nLanguage;
00231     } TT_CMAP_ENCODING_HEADER;
00232 
00233     typedef struct _tagTT_CMAP_ENCODING_0{
00234         TT_CMAP_ENCODING_HEADER header;
00235         unsigned char * pGlyphIdArray;
00236     } TT_CMAP_ENCODING_0;
00237 
00238     typedef struct _tagTT_CMAP_ENCODING_2_SUBHEADER{
00239         unsigned short nFirstCode;
00240         unsigned short nEntryCount;
00241         short nIdDelta;
00242         unsigned short nIdRangeOffset;
00243     } TT_CMAP_ENCODING_2_SUBHEADER;
00244 
00245     typedef struct _tagTT_CMAP_ENCODING_2{
00246         TT_CMAP_ENCODING_HEADER header;
00247         unsigned short subHeaderKeys[256];
00248         TT_CMAP_ENCODING_2_SUBHEADER* pSubHeaders; //[]
00249         //unsigned short[] pGlyphIndexArray;
00250     } TT_CMAP_ENCODING_2;
00251 
00252     typedef struct _tagTT_CMAP_ENCODING_4{
00253         TT_CMAP_ENCODING_HEADER header;
00254         unsigned short nSegCountX2;                 //2 x segCount
00255         unsigned short nSearchRange;                //2 x (2**floor(log2(segCount)))
00256         unsigned short nEntrySelector;              //log2(searchRange/2)
00257         unsigned short nRangeShift;                 //2 x segCount - searchRange
00258         //unsigned short endCount[segCount];        //End character code for each segment, last=0xFFFF
00259         //unsigned short reservePad;                //Set to 0
00260         //unsigned short startCount[segCount];      //Start character code for each segment
00261         //short idDelta[segCount]                   //Delta for all character codes in segment
00262         //unsigned short idrangeOffset[segCount];   //Offsets into glyphIdArray or 0
00263         //unsigned short glyphIdArray[]             //Glyph index array (arbitrary length)
00264     } TT_CMAP_ENCODING_4;
00265 
00266     typedef struct _tagTT_CMAP_ENCODING_6{
00267         TT_CMAP_ENCODING_HEADER header;
00268     } TT_CMAP_ENCODING_6;
00269 
00270     typedef struct _tagTT_CMAP_ENCODING_8{
00271         TT_CMAP_ENCODING_HEADER header;
00272     } TT_CMAP_ENCODING_8;
00273 
00274     typedef struct _tagTT_CMAP_ENCODING_10{
00275         TT_CMAP_ENCODING_HEADER header;
00276     } TT_CMAP_ENCODING_10;
00277 
00278     typedef struct _tagTT_CMAP_ENCODING_12{
00279         TT_CMAP_ENCODING_HEADER header;
00280     } TT_CMAP_ENCODING_12;
00281 
00282     class CachedTTFFontData
00283     {
00284     public:
00285         typedef std::map <unsigned short, unsigned short > tGlyphIndexMap;
00286 
00287         unsigned short nUnitsPerEM;
00288         TT_HHEA_TABLE_HEADER ttTblHHEA;
00289         tGlyphIndexMap oGlyphIndexMap;
00290         TT_HORZ_METRIC **ppHorzMetrics;
00291         TT_CMAP_ENCODING_HEADER **ppCMapTable;
00292                 int nEncodingID;//1  Unicode; 0  Symbol.
00293 
00294         CachedTTFFontData()
00295             : nUnitsPerEM(0)
00296             , ppHorzMetrics(NULL)
00297             , ppCMapTable(NULL)
00298             , nEncodingID(-1)
00299         {
00300             ttTblHHEA.nNumberOfHMetrics = 0;
00301         }
00302 
00303         ~CachedTTFFontData()
00304         {
00305             if (ppHorzMetrics)
00306             {
00307                 DWFCORE_FREE_MEMORY( *ppHorzMetrics );
00308                 DWFCORE_FREE_MEMORY( ppHorzMetrics );
00309             }
00310             if (ppCMapTable)
00311             {
00312                 DWFCORE_FREE_MEMORY( *ppCMapTable );
00313                 DWFCORE_FREE_MEMORY( ppCMapTable );
00314             }
00315         }
00316     };
00317 };
00319 
00320 
00321 #endif //XAML_FONT_HEADER

Generated on Tue Jan 6 22:40:06 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5