00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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