JPFont.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2006 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 #include "JPFont.h"
00021 #include "ShapeFont.h"
00022 #include "Shape.h"
00023 #include "ShapeFrame.h"
00024 #include "JPRenderedText.h"
00025 #include "encoding.h"
00026 
00027 DEFINE_RUNTIME_CLASSTYPE_CODE(JPFont,Pentagram::Font);
00028 
00029 
00030 JPFont::JPFont(ShapeFont* jpfont, unsigned int fontnum_)
00031         : fontnum(fontnum_), shapefont(jpfont)
00032 {
00033         assert(shapefont->frameCount() > 256);
00034 }
00035 
00036 
00037 JPFont::~JPFont()
00038 {
00039 
00040 }
00041 
00042 int JPFont::getWidth(int c)
00043 {
00044         return shapefont->getFrame(c)->width;
00045 }
00046 
00047 int JPFont::getHeight()
00048 {
00049         return shapefont->getHeight();
00050 }
00051 
00052 int JPFont::getBaseline()
00053 {
00054         return shapefont->getBaseline();
00055 }
00056 
00057 int JPFont::getBaselineSkip()
00058 {
00059         return shapefont->getBaselineSkip();
00060 }
00061 
00062 
00063 void JPFont::getStringSize(const std::string& text, int& width, int& height)
00064 {
00065         int hlead = shapefont->getHlead();
00066         width = hlead;
00067         height = getHeight();
00068 
00069         for (unsigned int i = 0; i < text.size(); ++i)
00070         {
00071                 if (text[i] == '\n' || text[i] == '\r') {
00072                         // ignore
00073                 } else {
00074                         uint16 sjis = text[i] & 0xFF;
00075                         if (sjis >= 0x80) {
00076                                 uint16 t = text[++i] & 0xFF;
00077                                 sjis += (t << 8);
00078                         }
00079                         width += getWidth(Pentagram::shiftjis_to_ultima8(sjis))-hlead;
00080                 }
00081         }
00082 }
00083 
00084 void JPFont::getTextSize(const std::string& text,
00085                                                  int& resultwidth, int& resultheight,
00086                                                  unsigned int& remaining,
00087                                                  int width, int height, TextAlign align,
00088                                                  bool u8specials)
00089 {
00090         std::list<PositionedText> tmp;
00091         tmp = typesetText<SJISTraits>(this, text, remaining,
00092                                                                   width, height, align, u8specials,
00093                                                                   resultwidth, resultheight);           
00094 }
00095 
00096 RenderedText* JPFont::renderText(const std::string& text,
00097                                                                  unsigned int& remaining,
00098                                                                  int width, int height, TextAlign align,
00099                                                                  bool u8specials,
00100                                                                  std::string::size_type cursor)
00101 {
00102         int resultwidth, resultheight;
00103         std::list<PositionedText> lines;
00104         lines = typesetText<SJISTraits>(this, text, remaining,
00105                                                                         width, height, align, u8specials,
00106                                                                         resultwidth, resultheight,
00107                                                                         cursor);
00108 
00109         return new JPRenderedText(lines, resultwidth, resultheight,
00110                                                           shapefont->getVlead(), shapefont, fontnum);
00111 }
00112 
00113 

Generated on Fri Jul 27 22:27:22 2007 for pentagram by  doxygen 1.4.7