comparison font/font_layout.cc @ 65:4416cfac86ae

Convert EUC-JP files to UTF8
author Thibaut Girka <thib@sitedethib.com>
date Fri, 26 Nov 2010 10:53:15 +0100
parents ddbcbd000206
children
comparison
equal deleted inserted replaced
64:045ca45f9610 65:4416cfac86ae
1 /* layout2.cc 1 /* layout2.cc
2 * テキストの禁則処理、レイアウトなどを行う 2 * 鴻胼ゃ≪茵
3 */ 3 */
4 /* 4 /*
5 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno 5 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
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; // 鴻宴若
44 44
45 class TextGlyphStreamHelper; 45 class TextGlyphStreamHelper;
46 46
47 enum KinsokuType { KinsokuHead = 1, KinsokuTail = 2}; 47 enum KinsokuType { KinsokuHead = 1, KinsokuTail = 2};
48 static int kinsoku_table1[] = { 48 static int kinsoku_table1[] = {
49 /* 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 */ 49 /* 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 */
50 0,0,2,2,2,2,0,0, /* X 、。,.・: */ 50 0,0,2,2,2,2,0,0, /* 鐚吾鐚鐚誌 */
51 0,2,2,0,0,0,0,0, /* ;?!゛゜´`¨ */ 51 0,2,2,0,0,0,0,0, /* 鐚鐚鐚卒鐔即 */
52 0,0,0,0,0,0,0,0, /* ^ ̄_ヽヾゝゞ〃 */ 52 0,0,0,0,0,0,0,0, /* 鐚常殖鐚帥純障 */
53 0,0,0,0,2,0,0,0, /* 仝々〆〇ー―‐/ */ 53 0,0,0,0,2,0,0,0, /* 篁錫鐚 */
54 0,2,0,0,2,2,1,2, /* \〜‖|…‥‘’ */ 54 0,2,0,0,2,2,1,2, /* 鐚若鐔モ */
55 1,2,1,2,1,2,1,2, /* “”()〔〕[] */ 55 1,2,1,2,1,2,1,2, /* 鐚鐚鐚誌悉 */
56 1,2,1,2,1,2,1,2, /* {}〈〉《》「」 */ 56 1,2,1,2,1,2,1,2, /* 鐔鐔 */
57 1,2,1,2,0,0,0,0, /* 『』【】+−±× */ 57 1,2,1,2,0,0,0,0, /* 鐚賊 */
58 0,0,0,0,0,0,0,0, /* ÷=≠<>≦≧∞ */ 58 0,0,0,0,0,0,0,0, /* 歎鐚鐚鐚р */
59 0,0,0,0,0,0,0,0, /* ∴♂♀°′″℃¥ */ 59 0,0,0,0,0,0,0,0, /* 癌属霞鰍鐃 */
60 0,0,0,0,0,0,0,0, /* $¢£%#&*@ */ 60 0,0,0,0,0,0,0,0, /* 鐚蔵贈鐚鐚鐚鐚鐚 */
61 0,0,0,0,0,0,0,0, /* §☆★○●◎◇X */ 61 0,0,0,0,0,0,0,0, /* 則鐚 */
62 0 62 0
63 }; 63 };
64 static int kinsoku_table2[] = { 64 static int kinsoku_table2[] = {
65 0,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0, /*  ぁあぃいぅうぇえぉおかがきぎく */ 65 0,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0, /* */
66 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ぐけげこごさざしじすずせぜそぞた */ 66 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
67 0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0, /* だちぢっつづてでとどなにぬねのは */ 67 0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0, /* <≪cゃャс */
68 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ばぱひびぴふぶぷへべぺほぼぽまみ */ 68 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 違宴蚊潟眼泣吟激吾鴻冴祉若純障 */
69 0,0,0,2,0,2,0,2,0,0,0,0,0,0,2,0, /* むめもゃやゅゆょよらりるれろゎわ */ 69 0,0,0,2,0,2,0,2,0,0,0,0,0,0,2,0, /* */
70 0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0, /* ゐゑをんヴヵヶ */ 70 0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0, /* 眼泣 */
71 0 71 0
72 }; 72 };
73 73
74 inline int Kinsoku(int code) { 74 inline int Kinsoku(int code) {
75 if ( (code&0xff80) == 0xa180) return kinsoku_table1[ (code&0xff) - 0xa0]; 75 if ( (code&0xff80) == 0xa180) return kinsoku_table1[ (code&0xff) - 0xa0];
119 data->font = font; 119 data->font = font;
120 } 120 }
121 121
122 TextGlyphStreamHelper::Iterator 122 TextGlyphStreamHelper::Iterator
123 TextGlyphStreamHelper::Add(int& x, TextGlyphStreamHelper::Iterator begin, TextGlyphStreamHelper::Iterator end, int max_x) { 123 TextGlyphStreamHelper::Add(int& x, TextGlyphStreamHelper::Iterator begin, TextGlyphStreamHelper::Iterator end, int max_x) {
124 /* text を glyph に変換する */ 124 /* text glyph 紊 */
125 TextGlyph gl; 125 TextGlyph gl;
126 Iterator it; 126 Iterator it;
127 gl.x = x; gl.y = 0; gl.r = r; gl.g = g; gl.b = b; gl.flag = TextGlyph::Flag(0); gl.is_rev = false; 127 gl.x = x; gl.y = 0; gl.r = r; gl.g = g; gl.b = b; gl.flag = TextGlyph::Flag(0); gl.is_rev = false;
128 for (it = begin; it != end; it++) { 128 for (it = begin; it != end; it++) {
129 if (it->type != TextElem::glyph) { 129 if (it->type != TextElem::glyph) {
162 Iterator it; 162 Iterator it;
163 it = sbegin; 163 it = sbegin;
164 if (it == send) return it; 164 if (it == send) return it;
165 if (it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_start) return sbegin; 165 if (it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_start) return sbegin;
166 it++; 166 it++;
167 /* まず、本文描画 */ 167 /* 障 */
168 int str_firstpos = data->size(); 168 int str_firstpos = data->size();
169 int str_width = 0; 169 int str_width = 0;
170 it = Add(str_width, it, send); 170 it = Add(str_width, it, send);
171 if (it == send || it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_startruby) { 171 if (it == send || it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_startruby) {
172 // ありえないはずだが、取り合えずなにもしないで終了 172 // х篋
173 cerr << "TextGlyphStream::AddRuby : invalid operation; fallback to the upeer level"<<endl; 173 cerr << "TextGlyphStream::AddRuby : invalid operation; fallback to the upeer level"<<endl;
174 data->erase(data->begin()+str_firstpos, data->end()); 174 data->erase(data->begin()+str_firstpos, data->end());
175 return sbegin+1; 175 return sbegin+1;
176 } 176 }
177 it++; 177 it++;
178 int str_lastpos = data->size()-1; 178 int str_lastpos = data->size()-1;
179 TextGlyph& str_first = data->begin()[str_firstpos]; 179 TextGlyph& str_first = data->begin()[str_firstpos];
180 TextGlyph& str_last = data->back(); 180 TextGlyph& str_last = data->back();
181 // 次に、フォントを取りかえてルビ描画 181 // 罨<潟
182 int ruby_firstpos = data->size(); 182 int ruby_firstpos = data->size();
183 XKFont::Face* save_font = face; 183 XKFont::Face* save_font = face;
184 if (ruby_face == 0) ruby_face = font->FaceLoad(ruby_scale); 184 if (ruby_face == 0) ruby_face = font->FaceLoad(ruby_scale);
185 face = ruby_face; 185 face = ruby_face;
186 int ruby_width = 0; 186 int ruby_width = 0;
187 it = Add(ruby_width, it, send); 187 it = Add(ruby_width, it, send);
188 if (it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_end) { 188 if (it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_end) {
189 /* ありえないはずだが、取り合えずなにもしないで終了 */ 189 /* х篋 */
190 cerr << "TextGlyphStream::AddRuby : invalid operation; fallback to the upeer level"<<endl; 190 cerr << "TextGlyphStream::AddRuby : invalid operation; fallback to the upeer level"<<endl;
191 data->erase(data->begin()+str_firstpos, data->end()); 191 data->erase(data->begin()+str_firstpos, data->end());
192 return sbegin+1; 192 return sbegin+1;
193 } 193 }
194 it++; 194 it++;
195 face = save_font; 195 face = save_font;
196 TextGlyph& ruby_first = (*data)[ruby_firstpos]; 196 TextGlyph& ruby_first = (*data)[ruby_firstpos];
197 TextGlyph& ruby_last = data->back(); 197 TextGlyph& ruby_last = data->back();
198 198
199 /* ルビを移動すべき高さを求める */ 199 /* 腱糸鴻蕭羆 */
200 int dummy, str_ascent, ruby_descent; 200 int dummy, str_ascent, ruby_descent;
201 CalcHeight(str_ascent, dummy, data->begin()+str_firstpos, data->begin()+ruby_firstpos); 201 CalcHeight(str_ascent, dummy, data->begin()+str_firstpos, data->begin()+ruby_firstpos);
202 CalcHeight(dummy, ruby_descent, data->begin()+ruby_firstpos, data->end()); 202 CalcHeight(dummy, ruby_descent, data->begin()+ruby_firstpos, data->end());
203 int ruby_height = str_ascent + ruby_descent + ruby_textskip; 203 int ruby_height = str_ascent + ruby_descent + ruby_textskip;
204 204
205 /* センタリングした場合の、ルビの左側、右側のマージン */ 205 /* 祉潟帥潟違翫綏眼勀眼若吾 */
206 int leftmergin, rightmergin; 206 int leftmergin, rightmergin;
207 leftmergin = str_first.glyph->advance.x/2 - (ruby_first.glyph->advance.x+1)/2; 207 leftmergin = str_first.glyph->advance.x/2 - (ruby_first.glyph->advance.x+1)/2;
208 rightmergin = str_last.glyph->advance.x/2 - (ruby_last.glyph->advance.x+1)/2; 208 rightmergin = str_last.glyph->advance.x/2 - (ruby_last.glyph->advance.x+1)/2;
209 209
210 /* ルビ、本文の横方向の移動 */ 210 /* 罔劫腱糸 */
211 int ruby_xstart_add = 0, ruby_xend_add = 0, str_xstart_add=0, str_xend_add = 0; 211 int ruby_xstart_add = 0, ruby_xend_add = 0, str_xstart_add=0, str_xend_add = 0;
212 if (ruby_width+leftmergin+rightmergin <= str_width) { // ルビの方が小さい 212 if (ruby_width+leftmergin+rightmergin <= str_width) { // 鴻絨
213 ruby_xstart_add = leftmergin; 213 ruby_xstart_add = leftmergin;
214 ruby_xend_add = str_width-rightmergin-ruby_width; 214 ruby_xend_add = str_width-rightmergin-ruby_width;
215 } else if (ruby_width <= str_width) { // マージンを減らす必要あり 215 } else if (ruby_width <= str_width) { // 若吾潟羝綽荀
216 leftmergin = (str_width-ruby_width)/2; 216 leftmergin = (str_width-ruby_width)/2;
217 ruby_xstart_add = leftmergin; 217 ruby_xstart_add = leftmergin;
218 ruby_xend_add = str_width-leftmergin-ruby_width; 218 ruby_xend_add = str_width-leftmergin-ruby_width;
219 } else { // ルビの方が大きい 219 } else { // 鴻紊с
220 int str_count = ruby_firstpos - str_firstpos; 220 int str_count = ruby_firstpos - str_firstpos;
221 str_xstart_add = ruby_width/str_count/2 - str_first.glyph->advance.x/2; 221 str_xstart_add = ruby_width/str_count/2 - str_first.glyph->advance.x/2;
222 str_xend_add = (ruby_width-str_width) - (ruby_width/str_count/2-str_last.glyph->advance.x/2); 222 str_xend_add = (ruby_width-str_width) - (ruby_width/str_count/2-str_last.glyph->advance.x/2);
223 str_width = ruby_width; 223 str_width = ruby_width;
224 } 224 }
225 AdjustPosition(str_xstart_add+x, str_xend_add+x, 0, data->begin()+str_firstpos, data->begin()+ruby_firstpos); 225 AdjustPosition(str_xstart_add+x, str_xend_add+x, 0, data->begin()+str_firstpos, data->begin()+ruby_firstpos);
226 AdjustPosition(ruby_xstart_add+x, ruby_xend_add+x, -ruby_height, data->begin()+ruby_firstpos, data->end()); 226 AdjustPosition(ruby_xstart_add+x, ruby_xend_add+x, -ruby_height, data->begin()+ruby_firstpos, data->end());
227 227
228 /* 本文が一文字ずつ表示されるように glyph の順番を入れかえ、グループ化 */ 228 /* 筝絖よ;腓冴 glyph ャ違若 */
229 vector<TextGlyph> save; 229 vector<TextGlyph> save;
230 save.assign(data->begin()+str_firstpos, data->end()); 230 save.assign(data->begin()+str_firstpos, data->end());
231 iterator it_str = save.begin(); 231 iterator it_str = save.begin();
232 iterator it_ruby = save.begin()+(ruby_firstpos-str_firstpos); 232 iterator it_ruby = save.begin()+(ruby_firstpos-str_firstpos);
233 iterator dit = data->begin()+str_firstpos; 233 iterator dit = data->begin()+str_firstpos;
256 return; 256 return;
257 } 257 }
258 258
259 void TextGlyphStreamHelper::AdjustPosition(int xstart_add, int xend_add, int y_add, TextGlyphStreamHelper::iterator begin, TextGlyphStreamHelper::iterator end) { 259 void TextGlyphStreamHelper::AdjustPosition(int xstart_add, int xend_add, int y_add, TextGlyphStreamHelper::iterator begin, TextGlyphStreamHelper::iterator end) {
260 iterator it; 260 iterator it;
261 /* 文字数を数える */ 261 /* 絖違違 */
262 int total_count = 0; 262 int total_count = 0;
263 for (it = begin; it != end; it++) { 263 for (it = begin; it != end; it++) {
264 if (it->flag & TextGlyph::Group) continue; 264 if (it->flag & TextGlyph::Group) continue;
265 total_count++; 265 total_count++;
266 } 266 }
267 /* 文字間のギャップを変更 */ 267 /* 絖c紊 */
268 int incr = 0; 268 int incr = 0;
269 if (total_count != 1) incr = (xend_add - xstart_add) * 256 / (total_count-1); 269 if (total_count != 1) incr = (xend_add - xstart_add) * 256 / (total_count-1);
270 int cur = xstart_add * 256; 270 int cur = xstart_add * 256;
271 for (it = begin; it != end; it++) { 271 for (it = begin; it != end; it++) {
272 it->x += cur / 256; 272 it->x += cur / 256;
276 } 276 }
277 return; 277 return;
278 } 278 }
279 void TextGlyphStreamHelper::CalcHeight(int& ascent_r, int& descent_r, TextGlyphStreamHelper::iterator begin, TextGlyphStreamHelper::iterator end) { 279 void TextGlyphStreamHelper::CalcHeight(int& ascent_r, int& descent_r, TextGlyphStreamHelper::iterator begin, TextGlyphStreamHelper::iterator end) {
280 iterator it; 280 iterator it;
281 /* 最大の descent, ascent を計算 */ 281 /* 紊с descent, ascent 荐膊 */
282 int ascent = 0; 282 int ascent = 0;
283 int descent = 0; 283 int descent = 0;
284 for (it = begin; it != end; it++) { 284 for (it = begin; it != end; it++) {
285 285
286 int y_top = it->y - it->glyph->bitmap_top; 286 int y_top = it->y - it->glyph->bitmap_top;
355 355
356 void TextHorizLayout::SetName(void) { 356 void TextHorizLayout::SetName(void) {
357 Iterator it; 357 Iterator it;
358 358
359 tab_width = 0; 359 tab_width = 0;
360 /* 行頭が名前なら、処理開始 */ 360 /* 茵紮 */
361 for (; pos != end; pos++) { 361 for (; pos != end; pos++) {
362 if (pos->type == TextElem::escape || pos->type == TextElem::glyph) break; 362 if (pos->type == TextElem::escape || pos->type == TextElem::glyph) break;
363 int x = 0; 363 int x = 0;
364 helper.Add(x, pos, pos+1); 364 helper.Add(x, pos, pos+1);
365 } 365 }
366 366
367 if (pos->type != TextElem::escape || pos->impl.Escape.type != TextElem::name_start) return; 367 if (pos->type != TextElem::escape || pos->impl.Escape.type != TextElem::name_start) return;
368 368
369 /* 名前をセットし、行頭の「の分を含めてタブ幅を設定する */ 369 /* 祉茵帥綛荐絎 */
370 pos++; 370 pos++;
371 for (it = pos; it != end; it++) { 371 for (it = pos; it != end; it++) {
372 if (it->type == TextElem::escape && it->impl.Escape.type == TextElem::name_end) break; 372 if (it->type == TextElem::escape && it->impl.Escape.type == TextElem::name_end) break;
373 } 373 }
374 if (it == end) return; 374 if (it == end) return;
375 int line_firstpos = data->size(); 375 int line_firstpos = data->size();
376 pos = helper.Add(tab_width, pos, it); 376 pos = helper.Add(tab_width, pos, it);
377 pos++; 377 pos++;
378 helper.SetGroup(data->begin() + line_firstpos, data->end()); 378 helper.SetGroup(data->begin() + line_firstpos, data->end());
379 379
380 // 行頭の「分を開ける 380 // 茵
381 try { 381 try {
382 tab_width += helper.CharWidth(0xa1d6); /* 「 */ 382 tab_width += helper.CharWidth(0xa1d6); /* */
383 } catch(...) {} 383 } catch(...) {}
384 384
385 return; 385 return;
386 }; 386 };
387 387
388 void TextHorizLayout::SetLineHead(void) { 388 void TextHorizLayout::SetLineHead(void) {
389 389
390 /* 行頭は 「などか? */ 390 /* 茵 鐚 */
391 391
392 for (; pos != end; pos++) { 392 for (; pos != end; pos++) {
393 if (pos->type == TextElem::escape || pos->type == TextElem::glyph) break; 393 if (pos->type == TextElem::escape || pos->type == TextElem::glyph) break;
394 int x = 0; 394 int x = 0;
395 helper.Add(x, pos, pos+1); 395 helper.Add(x, pos, pos+1);
396 } 396 }
397 if (pos->type != TextElem::glyph || Kinsoku(pos->impl.Glyph.code) != KinsokuHead) return; 397 if (pos->type != TextElem::glyph || Kinsoku(pos->impl.Glyph.code) != KinsokuHead) return;
398 398
399 /* 「なので、処理する */ 399 /* с */
400 if (tab_width != 0) tab_width -= helper.CharWidth(pos->impl.Glyph.code); 400 if (tab_width != 0) tab_width -= helper.CharWidth(pos->impl.Glyph.code);
401 int line_firstpos = data->size(); 401 int line_firstpos = data->size();
402 pos = helper.Add(tab_width, pos, pos+1); 402 pos = helper.Add(tab_width, pos, pos+1);
403 return; 403 return;
404 } 404 }
405 405
406 void TextHorizLayout::MakeLine(int line_start, int width, vector<int>& lineheights) { 406 void TextHorizLayout::MakeLine(int line_start, int width, vector<int>& lineheights) {
407 407
408 int x = tab_width; 408 int x = tab_width;
409 /* まず、全文字描画する */ 409 /* 障絖祉 */
410 while(pos != end) { 410 while(pos != end) {
411 pos = helper.Add(x, pos, end); 411 pos = helper.Add(x, pos, end);
412 if (pos->type == TextElem::escape && pos->impl.Escape.type == TextElem::ruby_start) { 412 if (pos->type == TextElem::escape && pos->impl.Escape.type == TextElem::ruby_start) {
413 pos = helper.AddRuby(x, pos, end); 413 pos = helper.AddRuby(x, pos, end);
414 } 414 }
415 if (pos != end && pos->type == TextElem::escape) { 415 if (pos != end && pos->type == TextElem::escape) {
416 if (pos->impl.Escape.type == TextElem::ret) break; 416 if (pos->impl.Escape.type == TextElem::ret) break;
417 if (pos->impl.Escape.type != TextElem::ruby_start) pos++; 417 if (pos->impl.Escape.type != TextElem::ruby_start) pos++;
418 } 418 }
419 } 419 }
420 /* 行に分割していく */ 420 /* 茵蚊 */
421 TextGlyphStream::iterator it_start = data->begin() + line_start; 421 TextGlyphStream::iterator it_start = data->begin() + line_start;
422 TextGlyphStream::iterator it_end = data->end(); 422 TextGlyphStream::iterator it_end = data->end();
423 TextGlyphStream::iterator it = it_start; 423 TextGlyphStream::iterator it = it_start;
424 424
425 TextGlyphStream::iterator group_head = it_start; 425 TextGlyphStream::iterator group_head = it_start;
426 int xstart = tab_width; 426 int xstart = tab_width;
427 int xend = width; 427 int xend = width;
428 while(it != it_end) { 428 while(it != it_end) {
429 // この行の終わりを決める 429 // 茵腟羆冴
430 bool is_ruby = false; 430 bool is_ruby = false;
431 TextGlyphStream::iterator it_line_start = it; 431 TextGlyphStream::iterator it_line_start = it;
432 for (; it != it_end; it++) { 432 for (; it != it_end; it++) {
433 if (it->x + it->glyph->advance.x > xend) break; 433 if (it->x + it->glyph->advance.x > xend) break;
434 if (it->flag & TextGlyph::Group) is_ruby = true; 434 if (it->flag & TextGlyph::Group) is_ruby = true;
435 if (!(it->flag & TextGlyph::Group)) group_head = it; 435 if (!(it->flag & TextGlyph::Group)) group_head = it;
436 } 436 }
437 // 水平移動の大きさを決める。デフォルトでタブ位置まで戻す 437 // 羂翫抗腱糸紊с羆冴с帥篏臀障ф祉
438 int xadd_start = -xstart + tab_width; 438 int xadd_start = -xstart + tab_width;
439 int xadd_end = xadd_start; 439 int xadd_end = xadd_start;
440 // it == 次行の先頭なので、今行の末尾へ戻す 440 // it == 罨∴с篁茵絨障御祉
441 // ただし、 最低一文字の表示は保証 441 // 篏筝絖茵腓冴篆荐
442 if (it != it_line_start && it != it_line_start+1 && it != it_end) it--; 442 if (it != it_line_start && it != it_line_start+1 && it != it_end) it--;
443 if (it != it_end) { 443 if (it != it_end) {
444 // グループ化されている文字で終了したら、前の文字に戻す 444 // 違若絖х篋絖祉
445 if (it->flag & TextGlyph::Group) it = group_head; 445 if (it->flag & TextGlyph::Group) it = group_head;
446 // 次が行頭禁則文字ならこの行に入れる 446 // 罨<茵胼絖茵ャ
447 if ( (it+1) != it_end && (it+1)->flag & TextGlyph::Kinsoku) it++; 447 if ( (it+1) != it_end && (it+1)->flag & TextGlyph::Kinsoku) it++;
448 // 移動する大きさを決める 448 // 腱糸紊с羆冴
449 // 行端ぞろえ、行末文字なら半文字分だけ突き出る 449 // 茵腴茵絖絖腦冴
450 int glyph_xend = it->x + it->glyph->advance.x; 450 int glyph_xend = it->x + it->glyph->advance.x;
451 if (it != it_line_start && (it-1)->flag & TextGlyph::Group) { // グループ化文字の場合、1文字前も見る 451 if (it != it_line_start && (it-1)->flag & TextGlyph::Group) { // 違若絖翫鐚絖荀
452 if (glyph_xend < (it-1)->x + (it-1)->glyph->advance.x) 452 if (glyph_xend < (it-1)->x + (it-1)->glyph->advance.x)
453 glyph_xend = (it-1)->x + (it-1)->glyph->advance.x; 453 glyph_xend = (it-1)->x + (it-1)->glyph->advance.x;
454 } 454 }
455 xadd_end += xend - glyph_xend; 455 xadd_end += xend - glyph_xend;
456 if (it->flag & TextGlyph::Kinsoku) 456 if (it->flag & TextGlyph::Kinsoku)
457 xadd_end += it->glyph->advance.x / 2; 457 xadd_end += it->glyph->advance.x / 2;
458 } 458 }
459 if (it != it_end) { 459 if (it != it_end) {
460 it->flag = TextGlyph::Flag(it->flag | TextGlyph::LineEnd); 460 it->flag = TextGlyph::Flag(it->flag | TextGlyph::LineEnd);
461 it++; // it == 次行の先頭へ 461 it++; // it == 罨∴
462 } 462 }
463 int ascent, descent; 463 int ascent, descent;
464 helper.CalcHeight(ascent, descent, it_start, it); 464 helper.CalcHeight(ascent, descent, it_start, it);
465 if (ascent+descent < helper.min_lineheight) { 465 if (ascent+descent < helper.min_lineheight) {
466 int dif = helper.min_lineheight-(ascent+descent); 466 int dif = helper.min_lineheight-(ascent+descent);
470 if (is_ruby) ascent+=ruby_lineskip; 470 if (is_ruby) ascent+=ruby_lineskip;
471 helper.AdjustPosition(xadd_start, xadd_end, cur_y+ascent+1, it_start, it); 471 helper.AdjustPosition(xadd_start, xadd_end, cur_y+ascent+1, it_start, it);
472 cur_y += ascent + descent + line_skip; 472 cur_y += ascent + descent + line_skip;
473 lineheights.push_back(ascent+descent+line_skip); 473 lineheights.push_back(ascent+descent+line_skip);
474 474
475 /* 次の行へ */ 475 /* 罨<茵 */
476 if (it != it_end) { 476 if (it != it_end) {
477 it_start = it; 477 it_start = it;
478 group_head = it_start; 478 group_head = it_start;
479 /* 1文字目がグループ化されていれば、グループの先頭文字にする */ 479 /* 鐚絖違若違違若絖 */
480 xstart = it->x; 480 xstart = it->x;
481 if (it->flag & TextGlyph::Group) { 481 if (it->flag & TextGlyph::Group) {
482 TextGlyphStream::iterator jit; 482 TextGlyphStream::iterator jit;
483 for (jit = it; jit != it_end; jit++) { 483 for (jit = it; jit != it_end; jit++) {
484 if (xstart > jit->x) xstart = jit->x; 484 if (xstart > jit->x) xstart = jit->x;
543 it--; 543 it--;
544 int y = it->y + it->glyph->bitmap.rows - it->glyph->bitmap_top; 544 int y = it->y + it->glyph->bitmap.rows - it->glyph->bitmap_top;
545 if (ymax < y) ymax = y; 545 if (ymax < y) ymax = y;
546 if (it == begin()) break; 546 if (it == begin()) break;
547 if (it->flag & TextGlyph::LineEnd) { 547 if (it->flag & TextGlyph::LineEnd) {
548 if (!(it->flag & TextGlyph::PhraseEnd)) break; // PhraseEnd は最後の文字 548 if (!(it->flag & TextGlyph::PhraseEnd)) break; // PhraseEnd 緇絖
549 } 549 }
550 } 550 }
551 return ymax + 1; 551 return ymax + 1;
552 } 552 }
553 553