diff --git a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_addon.java b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_addon.java new file mode 100644 index 000000000..de2776bc9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_addon.java @@ -0,0 +1,27 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import gplx.xowa.addons.*; +import gplx.xowa.bldrs.wkrs.*; +public class Hiero_addon implements Xoax_addon_itm, Xoax_addon_itm__init { + public void Init_addon_by_app(Xoa_app app) {} + public void Init_addon_by_wiki(Xow_wiki wiki) { + Hiero_hdump_wkr hdump_wkr = new Hiero_hdump_wkr(); + wiki.Html__hdump_mgr().Wkrs().Add(hdump_wkr.Key(), hdump_wkr); + } + + public String Addon__key() {return "xowa.hieros";} +} diff --git a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_hdump_wkr.java b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_hdump_wkr.java new file mode 100644 index 000000000..b3273bafd --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_hdump_wkr.java @@ -0,0 +1,34 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import gplx.langs.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.tags.*; +public class Hiero_hdump_wkr implements Xoh_hdump_wkr { + public byte[] Key() {return KEY;} + public int Process(Bry_bfr bfr, Xoh_hdoc_ctx hctx, Xoh_hdoc_wkr hdoc_wkr, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag tag) { + Gfh_atr atr = tag.Atrs__get_by_or_empty(Gfh_atr_.Bry__src); + if (atr == Gfh_atr.Noop) { + tag_rdr.Err_wkr().Warn("hiero tag missing src; tag=" + tag.To_str()); + bfr.Add_mid(src, tag.Src_bgn(), tag.Src_end()); + } + else { + Xoh_hdump_wkr_utl.Write_tag_with_val_at_atr_bgn(bfr, src, tag, atr, Hiero_xtn_mgr.Img_src_dir); + } + return tag.Src_end(); + } + + public static byte[] KEY = Bry_.new_a7("hiero-img"); + public static byte[] HDUMP_ATR = Xoh_hdump_wkr_utl.Build_hdump_atr(KEY); +} diff --git a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_fxt.java b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_fxt.java new file mode 100644 index 000000000..02e37c380 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_fxt.java @@ -0,0 +1,115 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2017 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.makes.tests.*; +class Hiero_html_fxt { + private final Hiero_html_mgr_fxt hiero_fxt = new Hiero_html_mgr_fxt(new Xop_fxt()); + private final Xoh_make_fxt make_fxt = new Xoh_make_fxt(); + private final Xop_fxt parser_fxt; + private String hdump_atr; + public Hiero_html_fxt() { + this.parser_fxt = hiero_fxt.Fxt(); + } + public Hiero_html_mgr_fxt Hiero_fxt() {return hiero_fxt;} + public Hiero_html_fxt Hdump_n_() {return Hdump_(Bool_.N);} + public Hiero_html_fxt Hdump_y_() {return Hdump_(Bool_.Y);} + private Hiero_html_fxt Hdump_(boolean v) { + this.hdump_atr = v ? " " + String_.new_u8(Hiero_hdump_wkr.HDUMP_ATR) : " "; + return this; + } + public void Test__hview(String wtxt, String expd) { + parser_fxt.Hctx_(Xoh_wtr_ctx.Basic); + parser_fxt.Test_html_full_str(wtxt, expd); + } + public void Test__hdump(String wtxt, String save, String load) { + parser_fxt.Hctx_(Xoh_wtr_ctx.Hdump); + parser_fxt.Test_html_full_str(wtxt, save); + make_fxt.Test__make(save, make_fxt.Page_chkr().Body_(load)); + } + public String Glyph_1__wtxt() { + hiero_fxt.Init_hiero_A1_B1(); + return "A1"; + } + public String Glyph_1__html(boolean hiero_dir_has_value) { + String hiero_dir = Hiero_dir(hiero_dir_has_value); + return String_.Concat_lines_nl + ( "" + , " " + , " " + , " " + , "
" + , " " + , " " + , " " + , " " + , "
" + , " A1" + , "
" + , "
" + ); + } + public String Cartouche__wtxt() { + hiero_fxt.Init_hiero_A1_B1().Init_hiero_cartouche(); + return "< A1 >"; + } + public String Cartouche__html(boolean hiero_dir_has_value) { + String hiero_dir = Hiero_dir(hiero_dir_has_value); + return String_.Concat_lines_nl_skip_last + ( "" + , " " + , " " + , " " + , "
" + , " " + , " " + , " " + , " " + , " " + , " " + , "
" + , " <" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
" + , "
" + , " " + , " " + , " " + , " " + , "
" + , " A1" + , "
" + , "
" + , "
" + , "
" + , " >" + , "
" + , "
" + ); + } + private String Hiero_dir(boolean hiero_dir_has_value) { + return hiero_dir_has_value ? "file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/" : ""; + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_tst.java b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_tst.java index f2f658f20..a37d21584 100644 --- a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_tst.java @@ -16,7 +16,12 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import org.junit.*; public class Hiero_html_mgr_tst { - @Before public void init() {fxt.Reset();} private Hiero_html_mgr_fxt fxt = new Hiero_html_mgr_fxt(new Xop_fxt()); + private Hiero_html_mgr_fxt fxt; + private final Hiero_html_fxt html_fxt = new Hiero_html_fxt(); + @Before public void init() { + fxt = html_fxt.Hiero_fxt(); + fxt.Reset(); + } @Test public void Empty() { fxt.Test_html_full_str ( "" @@ -31,24 +36,9 @@ public class Hiero_html_mgr_tst { )); } @Test public void Glyph_1() { - fxt.Init_hiero_A1_B1(); - fxt.Test_html_full_str - ( "A1" - , String_.Concat_lines_nl_skip_last - ( "" - , " " - , " " - , " " - , "
" - , " " - , " " - , " " - , " " - , "
" - , " A1" - , "
" - , "
" - )); + String wtxt = html_fxt.Glyph_1__wtxt(); + html_fxt.Test__hview(wtxt, html_fxt.Hdump_n_().Glyph_1__html(Bool_.Y)); + html_fxt.Test__hdump(wtxt, html_fxt.Hdump_y_().Glyph_1__html(Bool_.N), html_fxt.Glyph_1__html(Bool_.Y)); } @Test public void Mirrored() { fxt.Init_hiero_A1_B1(); @@ -181,50 +171,9 @@ public class Hiero_html_mgr_tst { )); } @Test public void Cartouche() { - fxt.Init_hiero_A1_B1().Init_hiero_cartouche(); - fxt.Test_html_full_str - ( "< A1 >" - , String_.Concat_lines_nl_skip_last - ( "" - , " " - , " " - , " " - , "
" - , " " - , " " - , " " - , " " - , " " - , " " - , "
" - , " <" - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , " " - , "
" - , "
" - , " " - , " " - , " " - , " " - , "
" - , " A1" - , "
" - , "
" - , "
" - , "
" - , " >" - , "
" - , "
" - )); + String wtxt = html_fxt.Cartouche__wtxt(); + html_fxt.Test__hview(wtxt, html_fxt.Hdump_n_().Cartouche__html(Bool_.Y)); + html_fxt.Test__hdump(wtxt, html_fxt.Hdump_y_().Cartouche__html(Bool_.N), html_fxt.Cartouche__html(Bool_.Y)); } @Test public void Superposition_regular() { fxt.Init_hiero_A1_B1(); diff --git a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_wtr.java b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_wtr.java index 7ad19248b..2290f10fd 100644 --- a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_wtr.java +++ b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_wtr.java @@ -83,14 +83,17 @@ class Hiero_html_wtr { 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 ? Gfh_entity_.Lt_bry : Gfh_entity_.Gt_bry; - return cartouche_img_fmtr.Bld_bry_many(temp_bfr, hiero_img_dir, code, height, title); + + // ISSUE#:553; DATE:2019-09-25 + byte[] img_src_dir = hiero_img_dir; + byte[] img_hdump_atr = Bry_.Empty; + if (hctx.Mode_is_hdump()) { + img_src_dir = Bry_.Empty; + img_hdump_atr = Hiero_hdump_wkr.HDUMP_ATR; + } + + return cartouche_img_fmtr.Bld_bry_many(temp_bfr, img_src_dir, code, height, title, img_hdump_atr); } - private static final Bry_fmtr cartouche_img_fmtr = Bry_fmtr.new_(String_.Concat - ( "\n ~{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 . "\n" . $tableContentHtml . ''; } @@ -132,8 +135,14 @@ class Hiero_html_wtr { } 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); + // ISSUE#:553; DATE:2019-09-25 + byte[] img_src_dir = hiero_img_dir; + byte[] img_hdump_atr = Bry_.Empty; + if (hctx.Mode_is_hdump()) { + img_src_dir = Bry_.Empty; + img_hdump_atr = Hiero_hdump_wkr.HDUMP_ATR; + } + return glyph_img_fmtr.Bld_bry_many(temp_bfr, img_cls, Hiero_html_mgr.Image_margin, td_height, img_src_dir, img_src_name, img_title, glyph, img_hdump_atr); } private static final byte[] Tbl_eol_bry = Bry_.new_a7(String_.Concat_lines_nl_skip_last @@ -143,14 +152,23 @@ class Hiero_html_wtr { , " " + Tbl_bgn_str , " " )); - private static final Bry_fmtr glyph_img_fmtr = Bry_fmtr.new_ - ( "\n ~{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; return void_fmtr.Bld_bry_many(temp_bfr, width); } + + private static final Bry_fmtr glyph_img_fmtr = Bry_fmtr.new_(String_.Concat + ( "\n " + , "~{glyph}" + ), "img_cls", "img_margin", "option", "hiero_img_dir", "img_code", "img_title", "glyph", "data-xowa-hdump"); + private static final Bry_fmtr cartouche_img_fmtr = Bry_fmtr.new_(String_.Concat + ( "\n " + , "~{title}" + ), "hiero_img_dir", "img_code", "height", "title", "data_xowa_hdump"); private static final Bry_fmtr void_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last ( "" , " " @@ -160,10 +178,4 @@ class Hiero_html_wtr { , " " , "
" ), "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") - ; } diff --git a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java index a221b6cc1..58782103a 100644 --- a/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java @@ -20,14 +20,17 @@ public class Hiero_xtn_mgr extends Xox_mgr_base implements Gfo_invk { @Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_a7("hiero"); @Override public Xox_mgr Xtn_clone_new() {return new Hiero_xtn_mgr();} public static byte[] Img_src_dir; - @Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {} + private Io_url ext_root_dir; + @Override public void Xtn_init_by_wiki(Xowe_wiki wiki) { + Xoae_app app = wiki.Appe(); + this.ext_root_dir = Hiero_root_dir(app.Fsys_mgr()); + Img_src_dir = ext_root_dir.GenSubDir("img").To_http_file_bry(); + } private static boolean xtn_init_done = false; public void Xtn_init_assert(Xowe_wiki wiki) { if (xtn_init_done) return; if (!Enabled()) return; Xoae_app app = wiki.Appe(); - Io_url ext_root_dir = Hiero_root_dir(app.Fsys_mgr()); - Img_src_dir = Bry_.new_u8(ext_root_dir.GenSubDir("img").To_http_file_str()); app.Gfs_mgr().Run_url_for(this, ext_root_dir.GenSubFil_nest("data", "tables.gfs")); html_wtr = new Hiero_html_mgr(this); parser.Init(); @@ -50,6 +53,8 @@ public class Hiero_xtn_mgr extends Xox_mgr_base implements Gfo_invk { else return super.Invk(ctx, ikey, k, m); } public static final String Invk_prefabs = "prefabs", Invk_files = "files", Invk_phonemes = "phonemes"; + + // DRD:allow overwriting hiero-dir public static void Hiero_root_dir_(Io_url v) {hiero_root_dir = v;} private static Io_url hiero_root_dir; public static Io_url Hiero_root_dir(Xoa_fsys_mgr fsys_mgr) {return hiero_root_dir == null ? fsys_mgr.Bin_xtns_dir().GenSubDir("Wikihiero") : hiero_root_dir;} }