mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.1.1
This commit is contained in:
@@ -19,7 +19,6 @@ package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
class Hiero_html_mgr {
|
||||
private Bry_bfr html_bfr = Bry_bfr.reset_(Io_mgr.Len_kb), content_bfr = Bry_bfr.reset_(255), tbl_content_bfr = Bry_bfr.reset_(Io_mgr.Len_kb), temp_bfr = Bry_bfr.reset_(255);
|
||||
private Xoh_wtr_ctx hctx;
|
||||
private boolean cartouche_opened = false;
|
||||
public static int scale = 100;
|
||||
private Hiero_prefab_mgr prefab_mgr; private Hiero_file_mgr file_mgr; private Hiero_phoneme_mgr phoneme_mgr;
|
||||
@@ -31,7 +30,7 @@ class Hiero_html_mgr {
|
||||
wtr = new Hiero_html_wtr(this, phoneme_mgr);
|
||||
}
|
||||
public void Render_blocks(Bry_bfr final_bfr, Xoh_wtr_ctx hctx, Hiero_block[] blocks, int scale, boolean hr_enabled) {
|
||||
this.hctx = hctx; wtr.Init_for_write(hctx);
|
||||
wtr.Init_for_write(hctx);
|
||||
Hiero_html_mgr.scale = scale;
|
||||
tbl_content_bfr.Clear(); content_bfr.Clear(); temp_bfr.Clear();
|
||||
cartouche_opened = false;
|
||||
@@ -41,9 +40,9 @@ class Hiero_html_mgr {
|
||||
for (int i = 0; i < blocks_len; i++) {
|
||||
Hiero_block block = blocks[i];
|
||||
if (block.Len() == 1)
|
||||
Render_block_single(content_bfr, hr_enabled, block);
|
||||
Render_block_single(content_bfr, hctx, hr_enabled, block);
|
||||
else
|
||||
Render_block_many(content_bfr, hr_enabled, block);
|
||||
Render_block_many(content_bfr, hctx, hr_enabled, block);
|
||||
if (content_bfr.Len_gt_0())
|
||||
tbl_content_bfr.Add_bfr_and_clear(content_bfr); // $tbl_content = $tbl + $content;
|
||||
}
|
||||
@@ -51,7 +50,7 @@ class Hiero_html_mgr {
|
||||
wtr.Tbl_inner(html_bfr, tbl_content_bfr);
|
||||
wtr.Tbl_outer(final_bfr, html_bfr);
|
||||
}
|
||||
private void Render_block_single(Bry_bfr content_bfr, boolean hr_enabled, Hiero_block block) {
|
||||
private void Render_block_single(Bry_bfr content_bfr, Xoh_wtr_ctx hctx, boolean hr_enabled, Hiero_block block) {
|
||||
byte[] code = block.Get_at(0); // block has only one code (hence the proc name: Render_block_single)
|
||||
byte b_0 = code[0];
|
||||
switch (b_0) {
|
||||
@@ -62,7 +61,7 @@ class Hiero_html_mgr {
|
||||
break;
|
||||
}
|
||||
case Byte_ascii.Lt: { // cartouche bgn
|
||||
wtr.Td(content_bfr, Render_glyph(Tkn_lt));
|
||||
wtr.Td(content_bfr, Render_glyph(hctx, Tkn_lt));
|
||||
cartouche_opened = true;
|
||||
wtr.Cartouche_bgn(content_bfr);
|
||||
break;
|
||||
@@ -70,17 +69,17 @@ class Hiero_html_mgr {
|
||||
case Byte_ascii.Gt: { // cartouche end
|
||||
wtr.Cartouche_end(content_bfr);
|
||||
cartouche_opened = false;
|
||||
wtr.Td(content_bfr, Render_glyph(Tkn_gt));
|
||||
wtr.Td(content_bfr, Render_glyph(hctx, Tkn_gt));
|
||||
break;
|
||||
}
|
||||
default: { // glyph or '.'
|
||||
byte[] td_height = wtr.Td_height(Resize_glyph(code, cartouche_opened));
|
||||
wtr.Td(content_bfr, Render_glyph(code, td_height));
|
||||
wtr.Td(content_bfr, Render_glyph(hctx, code, td_height));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Render_block_many(Bry_bfr content_bfr, boolean hr_enabled, Hiero_block block) {
|
||||
private void Render_block_many(Bry_bfr content_bfr, Xoh_wtr_ctx hctx, boolean hr_enabled, Hiero_block block) {
|
||||
temp_bfr.Clear(); // build prefab_bry: "convert all codes into '&' to test prefabs glyph"
|
||||
int block_len = block.Len();
|
||||
boolean amp = false;
|
||||
@@ -106,7 +105,7 @@ class Hiero_html_mgr {
|
||||
Hiero_prefab_itm prefab_itm = prefab_mgr.Get_by_key(prefab_bry);
|
||||
if (prefab_itm != null) {
|
||||
byte[] td_height = wtr.Td_height(Resize_glyph(prefab_bry, cartouche_opened));
|
||||
wtr.Td(content_bfr, Render_glyph(prefab_bry, td_height));
|
||||
wtr.Td(content_bfr, Render_glyph(hctx, prefab_bry, td_height));
|
||||
}
|
||||
else {
|
||||
int line_max = 0, total = 0, height = 0; // get block total height
|
||||
@@ -157,20 +156,19 @@ class Hiero_html_mgr {
|
||||
}
|
||||
// resize the glyph according to the block total height
|
||||
byte[] td_height = wtr.Td_height(Resize_glyph(v, cartouche_opened, total));
|
||||
temp_bfr.Add(Render_glyph(v, td_height));
|
||||
temp_bfr.Add(Render_glyph(hctx, v, td_height));
|
||||
}
|
||||
wtr.Td(content_bfr, temp_bfr.To_bry_and_clear());
|
||||
}
|
||||
}
|
||||
private byte[] Render_glyph(byte[] src) {return Render_glyph(src, Bry_.Empty);}
|
||||
private byte[] Render_glyph(byte[] src, byte[] td_height) {
|
||||
private byte[] Render_glyph(Xoh_wtr_ctx hctx, byte[] src) {return Render_glyph(hctx, src, Bry_.Empty);}
|
||||
private byte[] Render_glyph(Xoh_wtr_ctx hctx, byte[] src, byte[] td_height) {
|
||||
int src_len = src.length; if (src_len == 0) return src; // bounds check
|
||||
byte byte_n = src[src_len - 1];
|
||||
byte[] img_cls = byte_n == Byte_ascii.Backslash // REF.MW:isMirrored
|
||||
? Bry_cls_mirrored // 'class="mw-mirrored" '
|
||||
: Bry_.Empty
|
||||
;
|
||||
byte[] glyph = Extract_code(src, src_len); // trim backslashes from end; REF.MW:extractCode
|
||||
byte[] img_cls = byte_n == Byte_ascii.Backslash // REF.MW:isMirrored
|
||||
? Bry_cls_mirrored // 'class="mw-mirrored" '
|
||||
: Bry_.Empty;
|
||||
byte[] glyph = Extract_code(src, src_len); // trim backslashes from end; REF.MW:extractCode
|
||||
if (Bry_.Eq(glyph, Tkn_dot_dot)) // render void block
|
||||
return wtr.Void(Bool_.N);
|
||||
else if (Bry_.Eq(glyph, Tkn_dot)) // render 1/2 width void block
|
||||
@@ -182,18 +180,18 @@ class Hiero_html_mgr {
|
||||
|
||||
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph);
|
||||
Hiero_file_itm file_itm = null;
|
||||
byte[] glyph_esc = Html_utl.Escape_html_as_bry(glyph);
|
||||
byte[] glyph_esc = Gfh_utl.Escape_html_as_bry(glyph);
|
||||
if (phoneme_itm != null) {
|
||||
byte[] code = phoneme_itm.Gardiner_code();
|
||||
file_itm = file_mgr.Get_by_key(code);
|
||||
if (file_itm != null)
|
||||
return wtr.Img_phoneme(img_cls, td_height, glyph_esc, code);
|
||||
return wtr.Img_phoneme(hctx, img_cls, td_height, glyph_esc, code);
|
||||
else
|
||||
return glyph_esc;
|
||||
}
|
||||
file_itm = file_mgr.Get_by_key(glyph);
|
||||
return file_itm != null
|
||||
? wtr.Img_file(img_cls, td_height, glyph_esc)
|
||||
? wtr.Img_file(hctx, img_cls, td_height, glyph_esc)
|
||||
: glyph_esc
|
||||
;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ class Hiero_html_wtr {
|
||||
private Hiero_phoneme_mgr phoneme_mgr;
|
||||
private Bry_bfr temp_bfr = Bry_bfr.reset_(255);
|
||||
public Hiero_html_wtr(Hiero_html_mgr mgr, Hiero_phoneme_mgr phoneme_mgr) {this.phoneme_mgr = phoneme_mgr;}
|
||||
public void Init_for_write(Xoh_wtr_ctx hctx) {this.hiero_img_dir = hctx.Mode_is_hdump() ? gplx.xowa.htmls.core.makes.Xoh_make_trie_.Bry__hiero_dir : Hiero_xtn_mgr.Img_src_dir;} private byte[] hiero_img_dir = null;
|
||||
public void Hr(Bry_bfr bfr) {bfr.Add(Html_tag_.Hr_inl).Add_byte_nl();}
|
||||
public void Init_for_write(Xoh_wtr_ctx hctx) {this.hiero_img_dir = Hiero_xtn_mgr.Img_src_dir;} private byte[] hiero_img_dir = null;
|
||||
public void Hr(Bry_bfr bfr) {bfr.Add(Gfh_tag_.Hr_inl).Add_byte_nl();}
|
||||
public void Tbl_eol(Bry_bfr bfr) {bfr.Add(Tbl_eol_bry);}
|
||||
public byte[] Td_height(int height) {
|
||||
return temp_bfr.Add(Option_bgn_bry).Add_int_variable(height).Add(Option_end_bry).To_bry_and_clear();
|
||||
@@ -59,8 +59,7 @@ class Hiero_html_wtr {
|
||||
, " <td>"
|
||||
, " " + Tbl_bgn_str
|
||||
, " <tr>"
|
||||
))
|
||||
;
|
||||
));
|
||||
public void Cartouche_end(Bry_bfr bfr) {
|
||||
bfr.Add(Cartouche_end_lhs_bry).Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100).Add(Cartouche_end_rhs_bry);
|
||||
}
|
||||
@@ -85,7 +84,7 @@ class Hiero_html_wtr {
|
||||
int height = (int)((Hiero_html_mgr.Max_height * Hiero_html_mgr.scale) / 100);
|
||||
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph); if (phoneme_itm == null) throw Err_.new_wo_type("missing phoneme", "glyph", String_.new_u8(glyph));
|
||||
byte[] code = phoneme_itm.Gardiner_code();
|
||||
byte[] title = bgn ? Html_entity_.Lt_bry : Html_entity_.Gt_bry;
|
||||
byte[] title = bgn ? Gfh_entity_.Lt_bry : Gfh_entity_.Gt_bry;
|
||||
return cartouche_img_fmtr.Bld_bry_many(temp_bfr, hiero_img_dir, code, height, title);
|
||||
}
|
||||
private static final Bry_fmtr cartouche_img_fmtr = Bry_fmtr.new_(String_.Concat
|
||||
@@ -93,7 +92,7 @@ class Hiero_html_wtr {
|
||||
, " height='~{height}' title='~{title}'"
|
||||
, " alt='~{title}' />"
|
||||
)
|
||||
, "path", "code", "height", "title");
|
||||
, "path", "code", "height", "title", "hiero_tid");
|
||||
public void Tbl_inner(Bry_bfr html_bfr, Bry_bfr text_bfr) {
|
||||
html_bfr.Add(Tbl_inner_bgn).Add_bfr_and_clear(text_bfr).Add(Tbl_inner_end); // $html .= self::TABLE_START . "<tr>\n" . $tableContentHtml . '</tr></table>';
|
||||
}
|
||||
@@ -127,15 +126,14 @@ class Hiero_html_wtr {
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
))
|
||||
;
|
||||
public byte[] Img_phoneme(byte[] img_cls, byte[] td_height, byte[] glyph_esc, byte[] code) {
|
||||
byte[] code_esc = Html_utl.Escape_html_as_bry(temp_bfr, code);
|
||||
));
|
||||
public byte[] Img_phoneme(Xoh_wtr_ctx hctx, byte[] img_cls, byte[] td_height, byte[] glyph_esc, byte[] code) {
|
||||
byte[] code_esc = Gfh_utl.Escape_html_as_bry(temp_bfr, code);
|
||||
byte[] img_title = temp_bfr.Add(code_esc).Add_byte_space().Add_byte(Byte_ascii.Brack_bgn).Add(glyph_esc).Add_byte(Byte_ascii.Brack_end).To_bry_and_clear(); // "~{code} [~{glyph}]"
|
||||
return Img(img_cls, td_height, glyph_esc, code_esc, img_title);
|
||||
return Img(hctx, img_cls, td_height, glyph_esc, code_esc, img_title);
|
||||
}
|
||||
public byte[] Img_file(byte[] img_cls, byte[] td_height, byte[] glyph_esc) {return Img(img_cls, td_height, glyph_esc, glyph_esc, glyph_esc);}
|
||||
private byte[] Img(byte[] img_cls, byte[] td_height, byte[] glyph, byte[] img_src_name, byte[] img_title) {
|
||||
public byte[] Img_file(Xoh_wtr_ctx hctx, byte[] img_cls, byte[] td_height, byte[] glyph_esc) {return Img(hctx, img_cls, td_height, glyph_esc, glyph_esc, glyph_esc);}
|
||||
private byte[] Img(Xoh_wtr_ctx hctx, byte[] img_cls, byte[] td_height, byte[] glyph, byte[] img_src_name, byte[] img_title) {
|
||||
byte[] img_src = Bld_img_src(hiero_img_dir, img_src_name);
|
||||
return glyph_img_fmtr.Bld_bry_many(temp_bfr, img_cls, Hiero_html_mgr.Image_margin, td_height, img_src, img_title, glyph);
|
||||
}
|
||||
@@ -147,10 +145,9 @@ class Hiero_html_wtr {
|
||||
, " " + Tbl_bgn_str
|
||||
, " <tr>"
|
||||
));
|
||||
private static final Bry_fmtr
|
||||
glyph_img_fmtr = Bry_fmtr.new_
|
||||
( "\n <img ~{img_cls}style='margin: ~{img_margin}px; ~{option}' src='~{img_src}' title='~{img_title}' alt='~{glyph}' />", "img_cls", "img_margin", "option", "img_src", "img_title", "glyph")
|
||||
;
|
||||
private static final Bry_fmtr glyph_img_fmtr = Bry_fmtr.new_
|
||||
( "\n <img ~{img_cls}style='margin: ~{img_margin}px; ~{option}' src='~{img_src}' title='~{img_title}' alt='~{glyph}' />"
|
||||
, "img_cls", "img_margin", "option", "img_src", "img_title", "glyph");
|
||||
public byte[] Void(boolean half) { // render void
|
||||
int width = Hiero_html_mgr.Max_height;
|
||||
if (half) width /= 2;
|
||||
@@ -164,10 +161,11 @@ class Hiero_html_wtr {
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
)
|
||||
, "width");
|
||||
), "width");
|
||||
private static byte[] Bld_img_src(byte[] hiero_img_dir, byte[] name) {
|
||||
return Bry_.Add(hiero_img_dir, Img_src_prefix, name, Img_src_ext);
|
||||
}
|
||||
private static final byte[] Img_src_prefix = Bry_.new_a7("hiero_"), Img_src_ext = Bry_.new_a7(".png");
|
||||
private static final byte[] Img_src_prefix = Bry_.new_a7("hiero_")
|
||||
, Img_src_ext = Bry_.new_a7(".png")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ class Hiero_parser {
|
||||
int new_pos = trie.Match_pos();
|
||||
switch (itm.Tid()) {
|
||||
case Hiero_parser_itm.Tid_comment:
|
||||
int end_comm = Bry_find_.Find_fwd(src, Html_tag_.Comm_end, new_pos, end);
|
||||
int end_comm = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_end, new_pos, end);
|
||||
if (end_comm == Bry_find_.Not_found) // --> not found; for now, ignore <!--
|
||||
pos = new_pos;
|
||||
else
|
||||
pos = end_comm + Html_tag_.Comm_end_len;
|
||||
pos = end_comm + Gfh_tag_.Comm_end_len;
|
||||
break;
|
||||
case Hiero_parser_itm.Tid_block_spr:
|
||||
New_block();
|
||||
@@ -106,7 +106,7 @@ class Hiero_parser {
|
||||
Init_itms(Hiero_parser_itm.Tid_tkn_spr, "*", ":", "(", ")");
|
||||
Init_itms(Hiero_parser_itm.Tid_dot, ".");
|
||||
Init_itms(Hiero_parser_itm.Tid_single_char , "!");
|
||||
Init_itms(Hiero_parser_itm.Tid_comment, Html_tag_.Comm_bgn_str);
|
||||
Init_itms(Hiero_parser_itm.Tid_comment, Gfh_tag_.Comm_bgn_str);
|
||||
}
|
||||
private void Init_itms(byte tid, String... keys) {
|
||||
int keys_len = keys.length;
|
||||
|
||||
Reference in New Issue
Block a user