00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024
00025 #include "cinder/Cinder.h"
00026 #include "cinder/Shape2d.h"
00027 #include "cinder/Exception.h"
00028 #include "cinder/DataSource.h"
00029
00030 #include <string>
00031 #include <vector>
00032
00033 #if defined( CINDER_COCOA )
00034 typedef struct CGFont *CGFontRef;
00035 #if defined( CINDER_COCOA )
00036 typedef const struct __CTFont * CTFontRef;
00037 #endif
00038 #elif defined( CINDER_MSW )
00039 #include <windows.h>
00040
00041 namespace Gdiplus {
00042 class Font;
00043 }
00044 #endif
00045
00046 namespace cinder {
00047
00048 class Font {
00049 public:
00050 typedef uint16_t Glyph;
00051
00053 Font() {}
00056 Font( const std::string &aName, float size );
00059 Font( DataSourceRef dataSource, float size );
00060
00061 const std::string& getName() const;
00062 std::string getFullName() const;
00063 float getSize() const;
00064
00065 float getLeading() const;
00066 float getAscent() const;
00067 float getDescent() const;
00068 size_t getNumGlyphs() const;
00069
00070 Glyph getGlyphIndex( size_t idx );
00071 Glyph getGlyphChar( char utf8Char );
00072 std::vector<Glyph> getGlyphs( const std::string &utf8String );
00074 Shape2d getGlyphShape( Glyph glyphIndex );
00075
00076 static const std::vector<std::string>& getNames( bool forceRefresh = false );
00077
00078 #if defined( CINDER_COCOA )
00079 CGFontRef getCgFontRef() const;
00080 #if defined( CINDER_MAC )
00081 CTFontRef getCtFontRef() const;
00082 #endif
00083 #elif defined( CINDER_MSW )
00084 ::LOGFONT getLogfont() const { return mObj->mLogFont; }
00085 const Gdiplus::Font* getGdiplusFont() const { return mObj->mGdiplusFont.get(); }
00086 #endif
00087
00088 private:
00089 class Obj {
00090 public:
00091 Obj( const std::string &aName, float aSize );
00092 Obj( DataSourceRef dataSource, float size );
00093 ~Obj();
00094
00095 void finishSetup();
00096
00097
00098 std::string mName;
00099 float mSize;
00100 #if defined( CINDER_COCOA )
00101 CGFontRef mCGFont;
00102 #if defined( CINDER_MAC )
00103 const struct __CTFont* mCTFont;
00104 #endif
00105 #elif defined( CINDER_MSW )
00106 ::TEXTMETRIC mTextMetric;
00107 ::LOGFONTW mLogFont;
00108 ::HFONT mHfont;
00109 shared_ptr<Gdiplus::Font> mGdiplusFont;
00110 std::vector<std::pair<uint16_t,uint16_t> > mUnicodeRanges;
00111 size_t mNumGlyphs;
00112 #endif
00113 };
00114
00115 shared_ptr<Obj> mObj;
00116
00117 public:
00119
00120 typedef shared_ptr<Obj> Font::*unspecified_bool_type;
00121 operator unspecified_bool_type() { return ( mObj.get() == 0 ) ? 0 : &Font::mObj; }
00122 void reset() { mObj.reset(); }
00124 };
00125
00126 class FontInvalidNameExc : public cinder::Exception {
00127 };
00128
00129 class FontGlyphFailureExc : public cinder::Exception {
00130 };
00131
00132 }