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 "ShapeFont.h"
00021 #include "Shape.h"
00022 #include "ShapeFrame.h"
00023 #include "ShapeRenderedText.h"
00024
00025 DEFINE_RUNTIME_CLASSTYPE_CODE_MULTI2(ShapeFont,Pentagram::Font,Shape);
00026
00027
00028 ShapeFont::ShapeFont(const uint8* data,uint32 size,
00029 const ConvertShapeFormat *format,
00030 const uint16 flexId, const uint32 shapenum)
00031 : Font(), Shape(data,size,format, flexId, shapenum),
00032 height(0), baseline(0), vlead(-1), hlead(0)
00033 {
00034
00035 }
00036
00037 ShapeFont::~ShapeFont()
00038 {
00039
00040 }
00041
00042
00043 int ShapeFont::getWidth(char c)
00044 {
00045 return getFrame(static_cast<unsigned char>(c))->width;
00046 }
00047
00048 int ShapeFont::getHeight()
00049 {
00050 if (height == 0)
00051 {
00052 for (uint32 i = 0; i < frameCount(); i++)
00053 {
00054 int h = getFrame(i)->height;
00055
00056 if (h > height) height = h;
00057 }
00058 }
00059
00060 return height;
00061 }
00062
00063 int ShapeFont::getBaseline()
00064 {
00065 if (baseline == 0)
00066 {
00067 for (uint32 i = 0; i < frameCount(); i++)
00068 {
00069 int b = getFrame(i)->yoff;
00070
00071 if (b > baseline) baseline = b;
00072 }
00073 }
00074
00075 return baseline;
00076 }
00077
00078 int ShapeFont::getBaselineSkip()
00079 {
00080 return getHeight() + getVlead();
00081 }
00082
00083 void ShapeFont::getStringSize(const std::string& text, int& width, int& height)
00084 {
00085 width = hlead;
00086 height = getHeight();
00087
00088 for (unsigned int i = 0; i < text.size(); ++i)
00089 {
00090 if (text[i] == '\n' || text[i] == '\r') {
00091
00092 } else {
00093 width += getWidth(text[i])-hlead;
00094 }
00095 }
00096 }
00097
00098 RenderedText* ShapeFont::renderText(const std::string& text,
00099 unsigned int& remaining,
00100 int width, int height, TextAlign align,
00101 bool u8specials,
00102 std::string::size_type cursor)
00103 {
00104 int resultwidth, resultheight;
00105 std::list<PositionedText> lines;
00106 lines = typesetText<Traits>(this, text, remaining,
00107 width, height, align, u8specials,
00108 resultwidth, resultheight, cursor);
00109
00110 return new ShapeRenderedText(lines, resultwidth, resultheight,
00111 getVlead(), this);
00112 }