OSDN Git Service

NSDフォントプラグイン登録
[kimikage-nscr/kimikage-nscr.git] / nsdfont / src / Typesetter.cpp
1 /*\r
2  *      Kimikage NScripter Plugins Project\r
3  *\r
4  *      This software is distributed under a BSD-style license.\r
5  *      See license.txt for more information.\r
6  */\r
7 \r
8 #include "Typesetter.h"\r
9 \r
10 namespace nsdfont\r
11 {\r
12         Typesetter::Typesetter( void )\r
13         {\r
14         }\r
15 \r
16         Typesetter::~Typesetter( void )\r
17         {\r
18         }\r
19 \r
20         void Typesetter::setSpace( int horizontal, int vertical )\r
21         {\r
22                 hSpace = horizontal;\r
23                 vSpace = vertical;\r
24         }\r
25         \r
26         void Typesetter::calculateRect( int &width, int &height, \r
27                                                                         UnicodeString &str, const Decorator &decorator ) const\r
28         {\r
29                 str.rewind();\r
30                 width = 0;\r
31                 height = 0;\r
32                 int x = 0;\r
33                 int y = 0;\r
34                 int lineHeight = 0; // \8c»\8dÝ\91Î\8fÛ\82Æ\82µ\82Ä\82¢\82é\8ds\82Ì\8d\82\82³\r
35                 while( const unsigned int unicode = str.peek() )\r
36                 {\r
37                         const Glyph &glyph = *Glyph::get( unicode );\r
38                         if ( '\n' == unicode ) // \89ü\8ds\r
39                         {\r
40                                 if ( x > hSpace ) x -= hSpace;\r
41                                 if ( x > width ) width = x;\r
42                                 x = 0;\r
43                                 y += glyph.getAscent() + glyph.getDescent(); //1\95\8e\9a\82Ì\8d\82\82³\95ª\89º\82É\88Ú\93®\r
44                                 y += vSpace; // \8ds\8aÔ\95ª\88Ú\93®\r
45                                 lineHeight = 0;\r
46                                 continue;\r
47                         }\r
48                         const int bottom = glyph.getAscent() - glyph.getY() + glyph.getHeight();\r
49                         if ( bottom > lineHeight ) lineHeight = bottom;\r
50                         x += glyph.getCellWidth();\r
51                         x += hSpace;\r
52                 }\r
53                 if ( x > hSpace ) x -= hSpace;\r
54                 if ( x > width ) width = x;\r
55                 height = y + lineHeight;\r
56                 \r
57                 int exTop,exLeft,exBottom,exRight;\r
58                 decorator.getExtensionSize( exLeft, exTop, exRight, exBottom );\r
59                 width += exLeft + exRight;\r
60                 height+= exTop + exBottom;\r
61         }\r
62 \r
63         void Typesetter::draw( ArgbBitmap &bmp, UnicodeString &str, const Decorator &decorator ) const\r
64         {\r
65                 str.rewind();\r
66                 int x = 0;\r
67                 int y = 0;\r
68                 while( const unsigned int unicode = str.peek() )\r
69                 {\r
70                         const Glyph &glyph = *Glyph::get( unicode );\r
71                         if ( '\n' == unicode )\r
72                         {\r
73                                 x = 0;\r
74                                 y += glyph.getAscent() + glyph.getDescent();\r
75                                 y += vSpace;\r
76                                 continue;\r
77                         }\r
78                         const int gx = glyph.getX();\r
79                         const int gy = glyph.getAscent()-glyph.getY();\r
80 \r
81                         decorator.drawEdge( x + gx, y + gy, bmp, glyph );\r
82                         decorator.drawFace( x + gx, y + gy, bmp, glyph );\r
83 \r
84                         x += glyph.getCellWidth();\r
85                         x += hSpace;\r
86                 }\r
87         }\r
88 }