comparison font/font_layout.cc @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents 35ce1a30f3f9
children ddbcbd000206
comparison
equal deleted inserted replaced
51:cbb301016a4e 52:15a18fbe6f21
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include<vector> 31 #include <vector>
32 #include<map> 32 #include <map>
33 #include<iostream> 33 #include <iostream>
34 34
35 using namespace std; 35 using namespace std;
36 36
37 #include"font.h" 37 #include "font.h"
38 #include"text.h" 38 #include "text.h"
39 39
40 const int line_skip = 1; // 行と行の間の間隔 40 const int line_skip = 1; // 行と行の間の間隔
41 const int ruby_textskip = 0; // 文字とルビの間の間隔 41 const int ruby_textskip = 0; // 文字とルビの間の間隔
42 const int ruby_lineskip = 1; // ルビがあるときに行間に加える値 42 const int ruby_lineskip = 1; // ルビがあるときに行間に加える値
43 const double ruby_scale = 0.4; // ルビのスケール 43 const double ruby_scale = 0.4; // ルビのスケール
76 if ( (code&0xfe80) == 0xa480) return kinsoku_table2[ (code&0xff) - 0xa0]; /* code = 0xa400 / 0xa500 */ 76 if ( (code&0xfe80) == 0xa480) return kinsoku_table2[ (code&0xff) - 0xa0]; /* code = 0xa400 / 0xa500 */
77 return 0; 77 return 0;
78 } 78 }
79 79
80 class TextGlyphStreamHelper { 80 class TextGlyphStreamHelper {
81 typedef TextStream::Iterator Iterator; 81 private:
82 typedef TextGlyphStream::iterator iterator; 82 typedef TextStream::Iterator Iterator;
83 83 typedef TextGlyphStream::iterator iterator;
84 TextGlyphStream* data; 84
85 85 TextGlyphStream* data;
86 // information for rendering 86
87 unsigned char r, g, b; 87 // information for rendering
88 XKFont::Face* face; 88 unsigned char r, g, b;
89 XKFont::Face* ruby_face; 89 XKFont::Face* face;
90 XKFont::Font* font; 90 XKFont::Face* ruby_face;
91 91 XKFont::Font* font;
92 public: 92
93 int min_lineheight; 93 public:
94 TextGlyphStreamHelper(XKFont::Font* font); 94 int min_lineheight;
95 // helper functions 95 TextGlyphStreamHelper(XKFont::Font* font);
96 void Init(TextGlyphStream* data); 96 // helper functions
97 Iterator Add(int& x, Iterator begin, Iterator end, int max_x = 0); 97 void Init(TextGlyphStream* data);
98 Iterator AddRuby(int& x, Iterator begin, Iterator end); 98 Iterator Add(int& x, Iterator begin, Iterator end, int max_x = 0);
99 int CharWidth(int code); 99 Iterator AddRuby(int& x, Iterator begin, Iterator end);
100 void SetGroup(iterator begin, iterator end); 100 int CharWidth(int code);
101 void CalcHeight(int& ascent, int& descent, iterator begin, iterator end); 101 void SetGroup(iterator begin, iterator end);
102 void AdjustPosition(int xstart_add, int xend_add, int y_add, iterator begin, iterator end); 102 void CalcHeight(int& ascent, int& descent, iterator begin, iterator end);
103 void AdjustPosition(int xstart_add, int xend_add, int y_add, iterator begin, iterator end);
103 }; 104 };
104 105
105 TextGlyphStreamHelper::TextGlyphStreamHelper(XKFont::Font* __font) { 106 TextGlyphStreamHelper::TextGlyphStreamHelper(XKFont::Font* __font) {
106 font = __font; 107 font = __font;
107 face = font->FaceLoad(1.0); 108 face = font->FaceLoad(1.0);
490 return; 491 return;
491 } 492 }
492 493
493 namespace XKFont { 494 namespace XKFont {
494 495
495 HorizLayout::HorizLayout(const char* fontname, int size) { 496 HorizLayout::HorizLayout(const char* fontname, int size) {
496 font = new Font(fontname, size); 497 font = new Font(fontname, size);
497 pimpl = new ::TextHorizLayout(font); 498 pimpl = new ::TextHorizLayout(font);
498 } 499 }
499 500
500 HorizLayout::~HorizLayout() { 501 HorizLayout::~HorizLayout() {
501 delete pimpl; 502 delete pimpl;
502 delete font; 503 delete font;
503 } 504 }
504 505
505 void HorizLayout::Layout(TextStream& stream, TextGlyphStream& glyph, vector<int>& lineheights, int width) { 506 void HorizLayout::Layout(TextStream& stream, TextGlyphStream& glyph, vector<int>& lineheights, int width) {
506 pimpl->Layout(stream, glyph, lineheights, width); 507 pimpl->Layout(stream, glyph, lineheights, width);
507 }; 508 };
508 TextGlyphStream HorizLayout::Layout(const char* str, int width, int r, int gc, int b) { 509
509 TextStream s; 510 TextGlyphStream HorizLayout::Layout(const char* str, int width, int r, int gc, int b) {
510 s.SetColor(r,gc,b); 511 TextStream s;
511 s.Add(str); 512 s.SetColor(r,gc,b);
512 TextGlyphStream g; 513 s.Add(str);
513 vector<int> h; 514 TextGlyphStream g;
514 Layout(s, g, h, width); 515 vector<int> h;
515 return g; 516 Layout(s, g, h, width);
516 } 517 return g;
518 }
517 519
518 }; 520 };
519 521
520 int TextGlyphStream::width(void) { 522 int TextGlyphStream::width(void) {
521 if (empty()) return 0; 523 if (empty()) return 0;