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

font_data.h

00001 /*
00002   libwftk - Worldforge Toolkit - a widget library
00003   Copyright (C) 2003 Ron Steinke <rsteinke@w-link.net>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the
00017   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018   Boston, MA  02111-1307, SA.
00019 */
00020 
00021 #ifndef _FONT_DATA_H
00022 #define _FONT_DATA_H
00023 
00024 #include <wftk/font.h>
00025 
00026 #include <ft2build.h>
00027 #include FT_FREETYPE_H
00028 
00029 namespace wftk {
00030 
00031 // a wrapper around a freetype2 font face
00032 class FontData
00033 {
00034  public:
00035   FontData(const std::string& file, unsigned ptsize, unsigned face_index = 0)
00036     throw(Font::BadFont);
00037   FontData(const unsigned char* buffer, unsigned buf_size, unsigned ptsize,
00038     unsigned face_index = 0) throw(Font::BadFont);
00039   ~FontData();
00040 
00041   // glyph access
00042   FT_GlyphSlot operator[](unsigned char);
00043 
00044   const Font::Metrics& metrics() const {return metrics_;}
00045 
00046   Font::SurfaceTable* ref(const Color& color) {return map_.ref(color);}
00047   void unref(const Color& color) {map_.unref(color);}
00048   bool empty() const {return map_.empty();}
00049 
00050   bool hasKerning() const {return FT_HAS_KERNING(face_);}
00051   Point getKerning(unsigned char prev, unsigned char next) const;
00052 
00053  private:
00054   // unimplemented
00055   FontData(const FontData&);
00056   FontData& operator=(const FontData&);
00057 
00058   static FT_Library lib_;
00059   static unsigned long lib_refcount_;
00060 
00061   static void reflib() throw(Font::BadFont);
00062   static void unreflib() throw();
00063 
00064   // return horizontal and vertical dots per inch,
00065   // FIXME this is currently just the value for a 17"
00066   // monitor and 1024x768, need some way to auto-detect
00067   // this
00068   static Point getDPI() {return Point(80, 80);}
00069 
00070   FT_Face face_;
00071 
00072   Font::Metrics metrics_;
00073 
00074   void setMetrics();
00075 
00076   Font::MapType map_;
00077 };
00078 
00079 } // namespace
00080 
00081 #endif

Generated Tue Aug 9 18:40:26 2005.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.