bezfont.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        bezfont.h
00012 // DESCRIPTION: Bezier Font Support methods
00013 // AUTHOR:      Tom Hudson
00014 // HISTORY:     Created 1 November 1995
00015 //**************************************************************************/
00016 
00017 #pragma once
00018 
00019 #include "maxheap.h"
00020 #include <WTypes.h>
00021 #include "coreexp.h"
00022 #include "strclass.h"
00023 
00024 // Forward references
00025 class BezFontManager;
00026 class ClassDesc;
00027 class DllDir;
00028 class BezierShape;
00029 
00030 class BezFontMetrics: public MaxHeapOperators {
00031     public:
00032         LONG   Height;
00033         LONG   Ascent;
00034         LONG   Descent;
00035         LONG   InternalLeading;
00036         LONG   ExternalLeading;
00037         LONG   AveCharWidth;
00038         LONG   MaxCharWidth;
00039         LONG   Weight;
00040         LONG   Overhang;
00041         LONG   DigitizedAspectX;
00042         LONG   DigitizedAspectY;
00043         BCHAR  FirstChar;
00044         BCHAR  LastChar;
00045         BCHAR  DefaultChar;
00046         BCHAR  BreakChar;
00047         BYTE   Italic;
00048         BYTE   Underlined;
00049         BYTE   StruckOut;
00050         BYTE   PitchAndFamily;
00051         BYTE   CharSet;
00052         DWORD  Flags;
00053         UINT   SizeEM;
00054         UINT   CellHeight;
00055         UINT   AvgWidth;
00056         CoreExport BezFontMetrics() {}  // To Do; Fill in fields with reasonable values
00057         CoreExport BezFontMetrics(NEWTEXTMETRIC *from);
00058     };
00059 
00060 // BezFontInfo type
00061 #define BEZFONT_TRUETYPE    0
00062 #define BEZFONT_OTHER       1
00063 
00064 // BezFontInfo flags
00065 // None currently defined
00066 
00067 class BezFontInfo: public MaxHeapOperators {
00068     public:
00069         MSTR name;
00070         MSTR style;
00071         int type;       // See above
00072         DWORD flags;    // See above
00073         BezFontMetrics metrics;
00074         BezFontInfo() {}
00075         BezFontInfo(MSTR n, MSTR s, int t, DWORD f, BezFontMetrics &m) { name=n; style=s; type=t; flags=f; metrics=m; }
00076         CoreExport BezFontInfo &operator=(BezFontInfo &from);
00077     };
00078 
00079 // A class for Dlls to use for info that will be sent back to them at load time
00080 class DllData: public MaxHeapOperators {
00081     public:
00082         DllData() {}
00083     };
00084 
00085 // This is a callback class which is used to process font enumerations
00086 class BezFontEnumProc: public MaxHeapOperators {
00087     public:
00088         virtual ~BezFontEnumProc() {}
00089         virtual BOOL CALLBACK Entry(BezFontInfo &info, LPARAM userInfo)=0;
00090     };
00091 
00092 // A special enumerator for the font manager
00093 class BezFontMgrEnumProc: public MaxHeapOperators {
00094     public:
00095         BezFontManager *mgr;
00096         CoreExport BOOL CALLBACK Entry(BezFontInfo &info, LPARAM userInfo, DllData *dllData);
00097         void SetMgr(BezFontManager *m) { mgr = m; }
00098     };
00099 
00100 // A class for listing font input dlls
00101 class BezFontDll: public MaxHeapOperators {
00102     public:
00103         ClassDesc* dll;
00104         BezFontDll() { dll = NULL; }
00105         BezFontDll(ClassDesc* d) { dll = d; }
00106     };
00107 
00108 typedef Tab<BezFontDll *> BezFontDllTab;
00109 
00110 // A class for providing access to required Max internals
00111 class FontMgrInterface: public MaxHeapOperators {
00112      public:
00113         virtual ~FontMgrInterface() {}
00114         virtual HINSTANCE   AppInst() = 0;
00115         virtual HWND        AppWnd() = 0;
00116         virtual DllDir*     AppDllDir() = 0;
00117         virtual int         GetFontDirCount() = 0;
00118         virtual const MCHAR* GetFontDir (int i) = 0;
00119     };
00120 
00121 typedef int BEZFONTHANDLE;
00122 
00123 // A class used for listing the fonts we currently have available
00124 class AvailableFont: public MaxHeapOperators {
00125     public:
00126         BezFontInfo info;
00127         DllData *dllData;
00128         INT_PTR dllIndex;   // The index of the DLL which provides this font (in BezFontDllTab)
00129         AvailableFont() { dllData = NULL; }
00130         AvailableFont(BezFontInfo &i, INT_PTR di, DllData *dd=NULL) { info=i; dllIndex=di; dllData=dd; }
00131         CoreExport ~AvailableFont();
00132     };
00133 
00134 typedef Tab<AvailableFont *> AvailableFontTab;
00135 
00136 // The basic bezier font class
00137 class BezFont: public MaxHeapOperators {
00138     public:
00139         CoreExport BezFont() { }
00140         CoreExport virtual ~BezFont();
00141         CoreExport virtual void EnumerateFonts(BezFontMgrEnumProc& proc, LPARAM userInfo)=0;
00142         CoreExport virtual int OpenFont(MSTR name, DWORD flags, DllData *dllData)=0;
00143         CoreExport virtual void CloseFont()=0;
00144         CoreExport virtual BOOL BuildCharacter(UINT index, float height, BezierShape& shape, float& width, int fontShapeVersion=1)=0;
00145     };
00146 
00147 // A class used to list the fonts currently open
00148 class OpenBezFont: public MaxHeapOperators {
00149     public:
00150         int index;              // The index in AvailableFont
00151         DWORD flags;            // The style flags
00152         BEZFONTHANDLE handle;   // The handle we know it by
00153         int count;              // The number of users
00154         BezFont *loader;        // The loader for the font
00155         OpenBezFont() {}
00156         OpenBezFont(int i, DWORD f, BEZFONTHANDLE h, BezFont *l) { index=i; flags=f; handle=h; count=1; loader=l; }
00157         ~OpenBezFont();
00158     };
00159 
00160 typedef Tab<OpenBezFont *> OpenBezFontTab;
00161 
00162 // This is the interface into Bezier fonts within the MAX system.
00163 // This includes TrueType fonts and any other fonts supported via
00164 // plugins.
00165 
00166 // OpenFont flags
00167 // None currently defined
00168 
00169 class BezFontManager: public MaxHeapOperators {
00170     friend class BezFontMgrEnumProc;
00171 
00172     private:
00173         FontMgrInterface *iface;
00174         BOOL initialized;
00175         BezFontDllTab dllTab;
00176         AvailableFontTab available;
00177         OpenBezFontTab open;
00178         BezFontMgrEnumProc enumProc;            // What we use to get the available fonts
00179     public:
00180         CoreExport BezFontManager();
00181         CoreExport ~BezFontManager();
00182         CoreExport void SetInterface(FontMgrInterface *i) { iface = i; }
00183         CoreExport void Init();
00184         CoreExport void Uninit();
00185         CoreExport void Reinit();
00186         CoreExport void EnumerateFonts(BezFontEnumProc &proc, LPARAM userInfo);
00187         CoreExport BOOL FontExists(MSTR name);          // Returns TRUE if the font is available
00188         CoreExport BEZFONTHANDLE OpenFont(MSTR name, DWORD flags);
00189         CoreExport BOOL CloseFont(BEZFONTHANDLE handle);    // Returns TRUE if the font is still in use
00190         CoreExport BOOL BuildCharacter(BEZFONTHANDLE handle, UINT index, float height, BezierShape& shape, float &width, int fontShapeVersion=1);
00191         CoreExport FontMgrInterface *GetInterface() { return iface; }
00192         CoreExport BOOL GetFontInfo(MSTR name, BezFontInfo &info);
00193     };
00194 
00195 extern CoreExport BezFontManager theBezFontManager;
00196