Mercurial > otakunoraifu
diff 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 |
line wrap: on
line diff
--- a/font/font_layout.cc +++ b/font/font_layout.cc @@ -1,5 +1,5 @@ /* layout2.cc - * テキストの禁則処理、レイアウトなどを行う + * 鴻胼ゃ≪茵 */ /* * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno @@ -37,37 +37,37 @@ using namespace std; #include "font.h" #include "text.h" -const int line_skip = 1; // 行と行の間の間隔 -const int ruby_textskip = 0; // 文字とルビの間の間隔 -const int ruby_lineskip = 1; // ルビがあるときに行間に加える値 -const double ruby_scale = 0.4; // ルビのスケール +const int line_skip = 1; // 茵茵 +const int ruby_textskip = 0; // 絖 +const int ruby_lineskip = 1; // 茵 +const double ruby_scale = 0.4; // 鴻宴若 class TextGlyphStreamHelper; enum KinsokuType { KinsokuHead = 1, KinsokuTail = 2}; static int kinsoku_table1[] = { /* 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 */ - 0,0,2,2,2,2,0,0, /* X 、。,.・: */ - 0,2,2,0,0,0,0,0, /* ;?!゛゜´`¨ */ - 0,0,0,0,0,0,0,0, /* ^ ̄_ヽヾゝゞ〃 */ - 0,0,0,0,2,0,0,0, /* 仝々〆〇ー―‐/ */ - 0,2,0,0,2,2,1,2, /* \〜‖|…‥‘’ */ - 1,2,1,2,1,2,1,2, /* “”()〔〕[] */ - 1,2,1,2,1,2,1,2, /* {}〈〉《》「」 */ - 1,2,1,2,0,0,0,0, /* 『』【】+−±× */ - 0,0,0,0,0,0,0,0, /* ÷=≠<>≦≧∞ */ - 0,0,0,0,0,0,0,0, /* ∴♂♀°′″℃¥ */ - 0,0,0,0,0,0,0,0, /* $¢£%#&*@ */ - 0,0,0,0,0,0,0,0, /* §☆★○●◎◇X */ + 0,0,2,2,2,2,0,0, /* 鐚吾鐚鐚誌 */ + 0,2,2,0,0,0,0,0, /* 鐚鐚鐚卒鐔即 */ + 0,0,0,0,0,0,0,0, /* 鐚常殖鐚帥純障 */ + 0,0,0,0,2,0,0,0, /* 篁錫鐚 */ + 0,2,0,0,2,2,1,2, /* 鐚若鐔モ */ + 1,2,1,2,1,2,1,2, /* 鐚鐚鐚誌悉 */ + 1,2,1,2,1,2,1,2, /* 鐔鐔 */ + 1,2,1,2,0,0,0,0, /* 鐚賊 */ + 0,0,0,0,0,0,0,0, /* 歎鐚鐚鐚р */ + 0,0,0,0,0,0,0,0, /* 癌属霞鰍鐃 */ + 0,0,0,0,0,0,0,0, /* 鐚蔵贈鐚鐚鐚鐚鐚 */ + 0,0,0,0,0,0,0,0, /* 則鐚 */ 0 }; static int kinsoku_table2[] = { - 0,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0, /* ぁあぃいぅうぇえぉおかがきぎく */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ぐけげこごさざしじすずせぜそぞた */ - 0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0, /* だちぢっつづてでとどなにぬねのは */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ばぱひびぴふぶぷへべぺほぼぽまみ */ - 0,0,0,2,0,2,0,2,0,0,0,0,0,0,2,0, /* むめもゃやゅゆょよらりるれろゎわ */ - 0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0, /* ゐゑをんヴヵヶ */ + 0,2,0,2,0,2,0,2,0,2,0,0,0,0,0,0, /* */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */ + 0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0, /* <≪cゃャс */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 違宴蚊潟眼泣吟激吾鴻冴祉若純障 */ + 0,0,0,2,0,2,0,2,0,0,0,0,0,0,2,0, /* */ + 0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0, /* 眼泣 */ 0 }; @@ -121,7 +121,7 @@ void TextGlyphStreamHelper::Init(TextGly TextGlyphStreamHelper::Iterator TextGlyphStreamHelper::Add(int& x, TextGlyphStreamHelper::Iterator begin, TextGlyphStreamHelper::Iterator end, int max_x) { - /* text を glyph に変換する */ + /* text glyph 紊 */ TextGlyph gl; Iterator it; gl.x = x; gl.y = 0; gl.r = r; gl.g = g; gl.b = b; gl.flag = TextGlyph::Flag(0); gl.is_rev = false; @@ -164,12 +164,12 @@ TextGlyphStreamHelper::Iterator TextGlyp if (it == send) return it; if (it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_start) return sbegin; it++; - /* まず、本文描画 */ + /* 障 */ int str_firstpos = data->size(); int str_width = 0; it = Add(str_width, it, send); if (it == send || it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_startruby) { - // ありえないはずだが、取り合えずなにもしないで終了 + // х篋 cerr << "TextGlyphStream::AddRuby : invalid operation; fallback to the upeer level"<<endl; data->erase(data->begin()+str_firstpos, data->end()); return sbegin+1; @@ -178,7 +178,7 @@ TextGlyphStreamHelper::Iterator TextGlyp int str_lastpos = data->size()-1; TextGlyph& str_first = data->begin()[str_firstpos]; TextGlyph& str_last = data->back(); - // 次に、フォントを取りかえてルビ描画 + // 罨<潟 int ruby_firstpos = data->size(); XKFont::Face* save_font = face; if (ruby_face == 0) ruby_face = font->FaceLoad(ruby_scale); @@ -186,7 +186,7 @@ TextGlyphStreamHelper::Iterator TextGlyp int ruby_width = 0; it = Add(ruby_width, it, send); if (it->type != TextElem::escape || it->impl.Escape.type != TextElem::ruby_end) { - /* ありえないはずだが、取り合えずなにもしないで終了 */ + /* х篋 */ cerr << "TextGlyphStream::AddRuby : invalid operation; fallback to the upeer level"<<endl; data->erase(data->begin()+str_firstpos, data->end()); return sbegin+1; @@ -196,27 +196,27 @@ TextGlyphStreamHelper::Iterator TextGlyp TextGlyph& ruby_first = (*data)[ruby_firstpos]; TextGlyph& ruby_last = data->back(); - /* ルビを移動すべき高さを求める */ + /* 腱糸鴻蕭羆 */ int dummy, str_ascent, ruby_descent; CalcHeight(str_ascent, dummy, data->begin()+str_firstpos, data->begin()+ruby_firstpos); CalcHeight(dummy, ruby_descent, data->begin()+ruby_firstpos, data->end()); int ruby_height = str_ascent + ruby_descent + ruby_textskip; - /* センタリングした場合の、ルビの左側、右側のマージン */ + /* 祉潟帥潟違翫綏眼勀眼若吾 */ int leftmergin, rightmergin; leftmergin = str_first.glyph->advance.x/2 - (ruby_first.glyph->advance.x+1)/2; rightmergin = str_last.glyph->advance.x/2 - (ruby_last.glyph->advance.x+1)/2; - /* ルビ、本文の横方向の移動 */ + /* 罔劫腱糸 */ int ruby_xstart_add = 0, ruby_xend_add = 0, str_xstart_add=0, str_xend_add = 0; - if (ruby_width+leftmergin+rightmergin <= str_width) { // ルビの方が小さい + if (ruby_width+leftmergin+rightmergin <= str_width) { // 鴻絨 ruby_xstart_add = leftmergin; ruby_xend_add = str_width-rightmergin-ruby_width; - } else if (ruby_width <= str_width) { // マージンを減らす必要あり + } else if (ruby_width <= str_width) { // 若吾潟羝綽荀 leftmergin = (str_width-ruby_width)/2; ruby_xstart_add = leftmergin; ruby_xend_add = str_width-leftmergin-ruby_width; - } else { // ルビの方が大きい + } else { // 鴻紊с int str_count = ruby_firstpos - str_firstpos; str_xstart_add = ruby_width/str_count/2 - str_first.glyph->advance.x/2; str_xend_add = (ruby_width-str_width) - (ruby_width/str_count/2-str_last.glyph->advance.x/2); @@ -225,7 +225,7 @@ TextGlyphStreamHelper::Iterator TextGlyp AdjustPosition(str_xstart_add+x, str_xend_add+x, 0, data->begin()+str_firstpos, data->begin()+ruby_firstpos); AdjustPosition(ruby_xstart_add+x, ruby_xend_add+x, -ruby_height, data->begin()+ruby_firstpos, data->end()); - /* 本文が一文字ずつ表示されるように glyph の順番を入れかえ、グループ化 */ + /* 筝絖よ;腓冴 glyph ャ違若 */ vector<TextGlyph> save; save.assign(data->begin()+str_firstpos, data->end()); iterator it_str = save.begin(); @@ -258,13 +258,13 @@ void TextGlyphStreamHelper::SetGroup(Tex void TextGlyphStreamHelper::AdjustPosition(int xstart_add, int xend_add, int y_add, TextGlyphStreamHelper::iterator begin, TextGlyphStreamHelper::iterator end) { iterator it; - /* 文字数を数える */ + /* 絖違違 */ int total_count = 0; for (it = begin; it != end; it++) { if (it->flag & TextGlyph::Group) continue; total_count++; } - /* 文字間のギャップを変更 */ + /* 絖c紊 */ int incr = 0; if (total_count != 1) incr = (xend_add - xstart_add) * 256 / (total_count-1); int cur = xstart_add * 256; @@ -278,7 +278,7 @@ void TextGlyphStreamHelper::AdjustPositi } void TextGlyphStreamHelper::CalcHeight(int& ascent_r, int& descent_r, TextGlyphStreamHelper::iterator begin, TextGlyphStreamHelper::iterator end) { iterator it; - /* 最大の descent, ascent を計算 */ + /* 紊с descent, ascent 荐膊 */ int ascent = 0; int descent = 0; for (it = begin; it != end; it++) { @@ -357,7 +357,7 @@ void TextHorizLayout::SetName(void) { Iterator it; tab_width = 0; - /* 行頭が名前なら、処理開始 */ + /* 茵紮 */ for (; pos != end; pos++) { if (pos->type == TextElem::escape || pos->type == TextElem::glyph) break; int x = 0; @@ -366,7 +366,7 @@ void TextHorizLayout::SetName(void) { if (pos->type != TextElem::escape || pos->impl.Escape.type != TextElem::name_start) return; - /* 名前をセットし、行頭の「の分を含めてタブ幅を設定する */ + /* 祉茵帥綛荐絎 */ pos++; for (it = pos; it != end; it++) { if (it->type == TextElem::escape && it->impl.Escape.type == TextElem::name_end) break; @@ -377,9 +377,9 @@ void TextHorizLayout::SetName(void) { pos++; helper.SetGroup(data->begin() + line_firstpos, data->end()); - // 行頭の「分を開ける + // 茵 try { - tab_width += helper.CharWidth(0xa1d6); /* 「 */ + tab_width += helper.CharWidth(0xa1d6); /* */ } catch(...) {} return; @@ -387,7 +387,7 @@ void TextHorizLayout::SetName(void) { void TextHorizLayout::SetLineHead(void) { - /* 行頭は 「などか? */ + /* 茵 鐚 */ for (; pos != end; pos++) { if (pos->type == TextElem::escape || pos->type == TextElem::glyph) break; @@ -396,7 +396,7 @@ void TextHorizLayout::SetLineHead(void) } if (pos->type != TextElem::glyph || Kinsoku(pos->impl.Glyph.code) != KinsokuHead) return; - /* 「なので、処理する */ + /* с */ if (tab_width != 0) tab_width -= helper.CharWidth(pos->impl.Glyph.code); int line_firstpos = data->size(); pos = helper.Add(tab_width, pos, pos+1); @@ -406,7 +406,7 @@ void TextHorizLayout::SetLineHead(void) void TextHorizLayout::MakeLine(int line_start, int width, vector<int>& lineheights) { int x = tab_width; - /* まず、全文字描画する */ + /* 障絖祉 */ while(pos != end) { pos = helper.Add(x, pos, end); if (pos->type == TextElem::escape && pos->impl.Escape.type == TextElem::ruby_start) { @@ -417,7 +417,7 @@ void TextHorizLayout::MakeLine(int line_ if (pos->impl.Escape.type != TextElem::ruby_start) pos++; } } - /* 行に分割していく */ + /* 茵蚊 */ TextGlyphStream::iterator it_start = data->begin() + line_start; TextGlyphStream::iterator it_end = data->end(); TextGlyphStream::iterator it = it_start; @@ -426,7 +426,7 @@ void TextHorizLayout::MakeLine(int line_ int xstart = tab_width; int xend = width; while(it != it_end) { - // この行の終わりを決める + // 茵腟羆冴 bool is_ruby = false; TextGlyphStream::iterator it_line_start = it; for (; it != it_end; it++) { @@ -434,21 +434,21 @@ void TextHorizLayout::MakeLine(int line_ if (it->flag & TextGlyph::Group) is_ruby = true; if (!(it->flag & TextGlyph::Group)) group_head = it; } - // 水平移動の大きさを決める。デフォルトでタブ位置まで戻す + // 羂翫抗腱糸紊с羆冴с帥篏臀障ф祉 int xadd_start = -xstart + tab_width; int xadd_end = xadd_start; - // it == 次行の先頭なので、今行の末尾へ戻す - // ただし、 最低一文字の表示は保証 + // it == 罨∴с篁茵絨障御祉 + // 篏筝絖茵腓冴篆荐 if (it != it_line_start && it != it_line_start+1 && it != it_end) it--; if (it != it_end) { - // グループ化されている文字で終了したら、前の文字に戻す + // 違若絖х篋絖祉 if (it->flag & TextGlyph::Group) it = group_head; - // 次が行頭禁則文字ならこの行に入れる + // 罨<茵胼絖茵ャ if ( (it+1) != it_end && (it+1)->flag & TextGlyph::Kinsoku) it++; - // 移動する大きさを決める - // 行端ぞろえ、行末文字なら半文字分だけ突き出る + // 腱糸紊с羆冴 + // 茵腴茵絖絖腦冴 int glyph_xend = it->x + it->glyph->advance.x; - if (it != it_line_start && (it-1)->flag & TextGlyph::Group) { // グループ化文字の場合、1文字前も見る + if (it != it_line_start && (it-1)->flag & TextGlyph::Group) { // 違若絖翫鐚絖荀 if (glyph_xend < (it-1)->x + (it-1)->glyph->advance.x) glyph_xend = (it-1)->x + (it-1)->glyph->advance.x; } @@ -458,7 +458,7 @@ void TextHorizLayout::MakeLine(int line_ } if (it != it_end) { it->flag = TextGlyph::Flag(it->flag | TextGlyph::LineEnd); - it++; // it == 次行の先頭へ + it++; // it == 罨∴ } int ascent, descent; helper.CalcHeight(ascent, descent, it_start, it); @@ -472,11 +472,11 @@ void TextHorizLayout::MakeLine(int line_ cur_y += ascent + descent + line_skip; lineheights.push_back(ascent+descent+line_skip); - /* 次の行へ */ + /* 罨<茵 */ if (it != it_end) { it_start = it; group_head = it_start; - /* 1文字目がグループ化されていれば、グループの先頭文字にする */ + /* 鐚絖違若違違若絖 */ xstart = it->x; if (it->flag & TextGlyph::Group) { TextGlyphStream::iterator jit; @@ -545,7 +545,7 @@ int TextGlyphStream::height(void) { if (ymax < y) ymax = y; if (it == begin()) break; if (it->flag & TextGlyph::LineEnd) { - if (!(it->flag & TextGlyph::PhraseEnd)) break; // PhraseEnd は最後の文字 + if (!(it->flag & TextGlyph::PhraseEnd)) break; // PhraseEnd 緇絖 } } return ymax + 1;