Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgfont_impl.cpp

Go to the documentation of this file.
00001 #include "pglog.h"
00002 #include "facecache.h"
00003 #include "pgfont.h"
00004 
00005 struct PG_FontDataInternal {
00006         PG_Color color;
00007    PG_Color highlightColor;
00008    int alpha;
00009         PG_Font::Style style;
00010 
00011         int size;
00012         int index;
00013         std::string name;
00014 
00015         Uint32 dummy1;
00016         Uint32 dummy2;
00017 
00018         PG_FontFaceCacheItem* FaceCache;
00019 
00020 };
00021 
00022 PG_Font::PG_Font(const std::string& fontfile, int size, int index) {
00023         my_internaldata = new PG_FontDataInternal;
00024         my_internaldata->FaceCache = NULL;
00025 
00026         my_internaldata->name = fontfile;
00027         my_internaldata->size = size;
00028         my_internaldata->index = index;
00029         my_internaldata->color.r = 255;
00030         my_internaldata->color.g = 255;
00031         my_internaldata->color.b = 255;
00032    my_internaldata->highlightColor.r = 180;
00033    my_internaldata->highlightColor.g = 180;
00034    my_internaldata->highlightColor.b = 180;
00035    my_internaldata->alpha = 255;
00036         my_internaldata->style = NORMAL;
00037 
00038         my_internaldata->FaceCache = PG_FontEngine::LoadFontFace(fontfile, size, index);
00039 
00040         if(my_internaldata->FaceCache == NULL) {
00041                 PG_LogERR("Unable to create font (name=\"%s\", size=\"%i\", index=\"%i\"", fontfile.c_str(), size, index);
00042         }
00043 }
00044 
00045 void PG_Font :: copy( const PG_Font& font )
00046 {
00047    // my_internaldata = font.my_internaldata;
00048    // my_internaldata->referenceCount++;
00049    my_internaldata = new PG_FontDataInternal;
00050    *my_internaldata = *font.my_internaldata;
00051 }
00052 
00053 void PG_Font :: unlink()
00054 {
00055    delete my_internaldata;
00056    my_internaldata = NULL;
00057 }
00058 
00059 
00060 PG_Font :: PG_Font( const PG_Font& font )
00061 {
00062    copy ( font );
00063 }
00064    
00065    
00066 
00067 PG_Font& PG_Font::operator= ( const PG_Font& font )
00068 {
00069    unlink();
00070    copy ( font );
00071    return *this;
00072 }
00073 
00074 
00075 PG_Font::~PG_Font()
00076 {
00077    unlink();
00078 }
00079 
00080 int PG_Font::GetFontAscender() {
00081         return my_internaldata->FaceCache ?
00082                FT_CEIL(FT_MulFix(my_internaldata->FaceCache->Face->ascender, my_internaldata->FaceCache->Face->size->metrics.y_scale)) : 0;
00083 }
00084 
00085 int PG_Font::GetFontDescender() {
00086         return my_internaldata->FaceCache ?
00087                FT_CEIL(FT_MulFix(my_internaldata->FaceCache->Face->descender, my_internaldata->FaceCache->Face->size->metrics.y_scale)) : 0;
00088 }
00089 
00090 int PG_Font::GetFontHeight() {
00091         return my_internaldata->FaceCache ?
00092                FT_CEIL(FT_MulFix(my_internaldata->FaceCache->Face->height, my_internaldata->FaceCache->Face->size->metrics.y_scale)) : 0;
00093 }
00094 
00095 void PG_Font::SetColor(const PG_Color& c) {
00096         my_internaldata->color = c;
00097 }
00098 
00099 void PG_Font::SetHighlightColor(const PG_Color& c) {
00100    my_internaldata->highlightColor = c;
00101 }
00102 
00103 PG_Color PG_Font::GetColor() {
00104    return my_internaldata->color;
00105 }
00106 
00107 PG_Color PG_Font::GetHighlightColor() {
00108         return my_internaldata->highlightColor;
00109 }
00110 
00111 void PG_Font::SetAlpha(int a) {
00112         my_internaldata->alpha = a;
00113 }
00114 
00115 int PG_Font::GetAlpha() {
00116         return my_internaldata->alpha;
00117 }
00118 
00119 void PG_Font::SetStyle(Style s) {
00120         my_internaldata->style = s;
00121 }
00122 
00123 PG_Font::Style PG_Font::GetStyle() {
00124         return my_internaldata->style;
00125 }
00126 
00127 bool PG_Font::SetName(const std::string& fontfile) {
00128         my_internaldata->name = fontfile;
00129         my_internaldata->FaceCache = PG_FontEngine::LoadFontFace(
00130                                          fontfile,
00131                                          GetSize(),
00132                                          GetIndex());
00133 
00134         if(my_internaldata->FaceCache == NULL) {
00135                 PG_LogERR("Unable to create font (name=\"%s\", size=\"%i\", index=\"%i\"",
00136                           GetName().c_str(),
00137                           GetSize(),
00138                           GetIndex());
00139         }
00140 
00141         return (my_internaldata->FaceCache != NULL);
00142 }
00143 
00144 const std::string& PG_Font::GetName() {
00145         return my_internaldata->name;
00146 }
00147 
00148 void PG_Font::SetSize(int s) {
00149         my_internaldata->size = s;
00150         my_internaldata->FaceCache = PG_FontEngine::LoadFontFace(
00151                                          GetName(),
00152                                          GetSize(),
00153                                          GetIndex());
00154 
00155 
00156         if(my_internaldata->FaceCache == NULL) {
00157                 PG_LogERR("Unable to create font (name=\"%s\", size=\"%i\", index=\"%i\"",
00158                           GetName().c_str(),
00159                           GetSize(),
00160                           GetIndex());
00161         }
00162 
00163 }
00164 
00165 int PG_Font::GetSize() {
00166         return my_internaldata->size;
00167 }
00168 
00169 PG_FontFaceCacheItem* PG_Font::GetFaceCache(int index) {
00170         return my_internaldata->FaceCache;
00171 }
00172 
00173 void PG_Font::SetIndex(int index) {
00174         my_internaldata->index = index;
00175 }
00176 
00177 int PG_Font::GetIndex() {
00178         return my_internaldata->index;
00179 }
00180 
00181 /*void PG_Font::SetFaceCache(PG_FontFaceCacheItem* cache, int index) {
00182         my_internaldata->FaceCache = cache;
00183 }*/

Generated on Tue Jun 24 01:27:48 2008 for Advanced Strategic Command by  doxygen 1.4.2