mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Source: Restore broken commit
This commit is contained in:
66
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_file_mgr.java
Normal file
66
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_file_mgr.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.dsvs.*;
|
||||
class Hiero_file_mgr implements Gfo_invk {
|
||||
private Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
private Hiero_file_srl srl;
|
||||
public Hiero_file_mgr() {srl = new Hiero_file_srl(this);}
|
||||
public int Len() {return hash.Count();}
|
||||
public Hiero_file_itm Get_at(int i) {return (Hiero_file_itm)hash.Get_at(i);}
|
||||
public void Add(byte[] key, int file_w, int file_h) {hash.Add(key, new Hiero_file_itm(key, file_w, file_h));}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Hiero_file_itm Get_by_key(byte[] key) {return (Hiero_file_itm)hash.Get_by(key);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_srl)) return srl;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_srl = "srl";
|
||||
}
|
||||
class Hiero_file_itm {
|
||||
public Hiero_file_itm(byte[] key, int file_w, int file_h) {this.key = key; this.file_w = file_w; this.file_h = file_h;}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public int File_w() {return file_w;} private int file_w;
|
||||
public int File_h() {return file_h;} private int file_h;
|
||||
}
|
||||
class Hiero_file_srl extends Dsv_wkr_base {
|
||||
private Hiero_file_mgr mgr;
|
||||
private byte[] key;
|
||||
private int file_w = -1, file_h = -1;
|
||||
public Hiero_file_srl(Hiero_file_mgr mgr) {this.mgr = mgr;}
|
||||
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Int_parser, Dsv_fld_parser_.Int_parser};}
|
||||
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
|
||||
switch (fld_idx) {
|
||||
case 0: key = Bry_.Mid(src, bgn, end); return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@Override public boolean Write_int(Dsv_tbl_parser parser, int fld_idx, int pos, int val_int) {
|
||||
switch (fld_idx) {
|
||||
case 1: file_w = val_int; return true;
|
||||
case 2: file_h = val_int; return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
|
||||
if (key == null) throw parser.Err_row_bgn("file missing key", pos);
|
||||
if (file_w == -1) throw parser.Err_row_bgn("file missing w", pos);
|
||||
if (file_h == -1) throw parser.Err_row_bgn("file missing h", pos);
|
||||
mgr.Add(key, file_w, file_h);
|
||||
key = null; file_w = file_h = -1;
|
||||
}
|
||||
}
|
||||
237
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr.java
Normal file
237
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr.java
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
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 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;
|
||||
private Hiero_html_wtr wtr;
|
||||
public Hiero_html_mgr(Hiero_xtn_mgr xtn_mgr) {
|
||||
prefab_mgr = xtn_mgr.Prefab_mgr();
|
||||
file_mgr = xtn_mgr.File_mgr();
|
||||
phoneme_mgr = xtn_mgr.Phoneme_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) {
|
||||
wtr.Init_for_write(hctx);
|
||||
Hiero_html_mgr.scale = scale;
|
||||
tbl_content_bfr.Clear(); content_bfr.Clear(); temp_bfr.Clear();
|
||||
cartouche_opened = false;
|
||||
if (hr_enabled)
|
||||
wtr.Hr(html_bfr);
|
||||
int blocks_len = blocks.length;
|
||||
for (int i = 0; i < blocks_len; i++) {
|
||||
Hiero_block block = blocks[i];
|
||||
if (block.Len() == 1)
|
||||
Render_block_single(content_bfr, hctx, hr_enabled, block);
|
||||
else
|
||||
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;
|
||||
}
|
||||
if (tbl_content_bfr.Len_gt_0())
|
||||
wtr.Tbl_inner(html_bfr, tbl_content_bfr);
|
||||
wtr.Tbl_outer(final_bfr, html_bfr);
|
||||
}
|
||||
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) {
|
||||
case Byte_ascii.Bang: { // new_line
|
||||
wtr.Tbl_eol(content_bfr);
|
||||
if (hr_enabled)
|
||||
wtr.Hr(content_bfr);
|
||||
break;
|
||||
}
|
||||
case Byte_ascii.Lt: { // cartouche bgn
|
||||
wtr.Td(content_bfr, Render_glyph(hctx, Tkn_lt));
|
||||
cartouche_opened = true;
|
||||
wtr.Cartouche_bgn(content_bfr);
|
||||
break;
|
||||
}
|
||||
case Byte_ascii.Gt: { // cartouche end
|
||||
wtr.Cartouche_end(content_bfr);
|
||||
cartouche_opened = false;
|
||||
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(hctx, code, td_height));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
for (int i = 0; i < block_len; i++) {
|
||||
byte[] v = block.Get_at(i);
|
||||
int v_len = v.length;
|
||||
amp = false;
|
||||
if (v_len == 1) {
|
||||
switch (v[0]) {
|
||||
case Byte_ascii.Brack_bgn: case Byte_ascii.Brack_end:
|
||||
case Byte_ascii.Paren_bgn: case Byte_ascii.Paren_end:
|
||||
case Byte_ascii.Star: case Byte_ascii.Colon: case Byte_ascii.Bang:
|
||||
amp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (amp)
|
||||
temp_bfr.Add_byte(Byte_ascii.Amp);
|
||||
else
|
||||
temp_bfr.Add(v);
|
||||
}
|
||||
byte[] prefab_bry = temp_bfr.To_bry_and_clear();
|
||||
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(hctx, prefab_bry, td_height));
|
||||
}
|
||||
else {
|
||||
int line_max = 0, total = 0, height = 0; // get block total height
|
||||
byte[] glyph = null;
|
||||
for (int i = 0; i < block_len; i++) {
|
||||
byte[] v = block.Get_at(i);
|
||||
int v_len = v.length;
|
||||
if (v_len == 1) {
|
||||
switch (v[0]) {
|
||||
case Byte_ascii.Colon:
|
||||
if (height > line_max)
|
||||
line_max = height;
|
||||
total += line_max;
|
||||
line_max = 0;
|
||||
continue;
|
||||
case Byte_ascii.Star:
|
||||
if (height > line_max)
|
||||
line_max = height;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(v);
|
||||
if (phoneme_itm != null)
|
||||
glyph = phoneme_itm.Gardiner_code();
|
||||
else
|
||||
glyph = v;
|
||||
Hiero_file_itm file_itm = file_mgr.Get_by_key(glyph);
|
||||
if (file_itm != null)
|
||||
height = 2 + file_itm.File_h();
|
||||
}
|
||||
if (height > line_max)
|
||||
line_max = height;
|
||||
total += line_max;
|
||||
|
||||
// render all glyph into the block
|
||||
for (int i = 0; i < block_len; i++) {
|
||||
byte[] v = block.Get_at(i);
|
||||
int v_len = v.length;
|
||||
if (v_len == 1) {
|
||||
switch (v[0]) {
|
||||
case Byte_ascii.Colon:
|
||||
temp_bfr.Add_str_a7("\n <br/>");
|
||||
continue;
|
||||
case Byte_ascii.Star:
|
||||
temp_bfr.Add_byte_space();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 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(hctx, v, td_height));
|
||||
}
|
||||
wtr.Td(content_bfr, temp_bfr.To_bry_and_clear());
|
||||
}
|
||||
}
|
||||
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
|
||||
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
|
||||
return wtr.Void(Bool_.Y);
|
||||
else if (Bry_.Eq(glyph, Tkn_lt))
|
||||
return wtr.Cartouche_img(hctx, Bool_.Y, glyph);
|
||||
else if (Bry_.Eq(glyph, Tkn_gt))
|
||||
return wtr.Cartouche_img(hctx, Bool_.N, glyph);
|
||||
|
||||
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph);
|
||||
Hiero_file_itm file_itm = null;
|
||||
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(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(hctx, img_cls, td_height, glyph_esc)
|
||||
: glyph_esc
|
||||
;
|
||||
}
|
||||
private int Resize_glyph(byte[] item, boolean cartouche_opened) {return Resize_glyph(item, cartouche_opened, 0);}
|
||||
private int Resize_glyph(byte[] item, boolean cartouche_opened, int total) {
|
||||
item = Extract_code(item, item.length);
|
||||
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(item);
|
||||
byte[] glyph = phoneme_itm == null ? item : phoneme_itm.Gardiner_code();
|
||||
int margin = 2 * Image_margin;
|
||||
if (cartouche_opened)
|
||||
margin += 2 * (int)((Cartouche_width * scale) / 100);
|
||||
Hiero_file_itm file_itm = file_mgr.Get_by_key(glyph);
|
||||
if (file_itm != null) {
|
||||
int height = margin + file_itm.File_h();
|
||||
if (total > 0) {
|
||||
return total > Max_height
|
||||
? (int)(((((height * Max_height) / total) - margin) * scale) / 100)
|
||||
: (int)(((height - margin) * scale) / 100)
|
||||
;
|
||||
}
|
||||
else {
|
||||
return height > Max_height
|
||||
? (int)(((((Max_height * Max_height) / height) - margin) * scale) / 100)
|
||||
: (int)(((height - margin) * scale) / 100)
|
||||
;
|
||||
}
|
||||
}
|
||||
return (int)(((Max_height - margin) * scale) / 100);
|
||||
}
|
||||
private static byte[] Extract_code(byte[] src, int src_len) { // trim backslashes from end; REF.MW:extractCode
|
||||
return Bry_.Trim_end(src, Byte_ascii.Backslash, src_len);
|
||||
}
|
||||
public static final int Image_margin = 1;
|
||||
public static final int Cartouche_width = 2;
|
||||
public static final int Max_height = 44;
|
||||
private static final byte[] Bry_cls_mirrored = Bry_.new_a7("class=\"mw-mirrored\" ");
|
||||
private static final byte[]
|
||||
Tkn_lt = new byte[] {Byte_ascii.Lt}
|
||||
, Tkn_gt = new byte[] {Byte_ascii.Gt}
|
||||
, Tkn_dot = new byte[] {Byte_ascii.Dot}
|
||||
, Tkn_dot_dot = new byte[] {Byte_ascii.Dot, Byte_ascii.Dot}
|
||||
;
|
||||
}
|
||||
56
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_fxt.java
Normal file
56
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_fxt.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Hiero_html_mgr_fxt {
|
||||
private Hiero_xtn_mgr xtn_mgr;
|
||||
public Hiero_html_mgr_fxt(Xop_fxt fxt) {this.fxt = fxt;}
|
||||
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt;
|
||||
public void Reset() {
|
||||
fxt.Reset();
|
||||
xtn_mgr = new Hiero_xtn_mgr();
|
||||
xtn_mgr.Xtn_init_by_app(fxt.App());
|
||||
xtn_mgr.Clear();
|
||||
}
|
||||
public Hiero_html_mgr_fxt Init_hiero_A1_B1() {
|
||||
this.Init_file("A1", 29, 38);
|
||||
this.Init_file("B1", 23, 38);
|
||||
return this;
|
||||
}
|
||||
public Hiero_html_mgr_fxt Init_hiero_cartouche() {
|
||||
this.Init_phoneme("<", "Ca1");
|
||||
this.Init_phoneme(">", "Ca2");
|
||||
return this;
|
||||
}
|
||||
public Hiero_html_mgr_fxt Init_hiero_p_t() {
|
||||
this.Init_phoneme("p", "Q3");
|
||||
this.Init_phoneme("t", "X1");
|
||||
this.Init_file("Q3", 12, 15);
|
||||
this.Init_file("X1", 20, 11);
|
||||
return this;
|
||||
}
|
||||
public Hiero_html_mgr_fxt Init_hiero_a_A1() {
|
||||
this.Init_prefab("a&A1");
|
||||
this.Init_file("a&A1", 37, 38);
|
||||
return this;
|
||||
}
|
||||
public Hiero_html_mgr_fxt Init_prefab(String prefab) {xtn_mgr.Prefab_mgr().Add(Bry_.new_u8(prefab)); return this;}
|
||||
public Hiero_html_mgr_fxt Init_file(String s, int w, int h) {xtn_mgr.File_mgr().Add(Bry_.new_u8(s), w, h); return this;}
|
||||
public Hiero_html_mgr_fxt Init_phoneme(String phoneme, String code) {xtn_mgr.Phoneme_mgr().Add(Bry_.new_u8(phoneme), Bry_.new_u8(code)); return this;}
|
||||
public void Test_html_full_str(String raw, String expd) {fxt.Test_html_full_str(raw, expd);}
|
||||
public void Test_html_full_frag(String raw, String expd) {fxt.Test_html_full_frag(raw, expd);}
|
||||
}
|
||||
389
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_tst.java
Normal file
389
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_mgr_tst.java
Normal file
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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());
|
||||
@Test public void Empty() {
|
||||
fxt.Test_html_full_str
|
||||
( "<hiero></hiero>"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, ""
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Glyph_1() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str
|
||||
( "<hiero>A1</hiero>"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Mirrored() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str
|
||||
( "<hiero>A1\\</hiero>"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img class=\"mw-mirrored\" style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Glyph_2() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str("<hiero>A1-B1</hiero>", String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " </td>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Void_half() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str
|
||||
( "<hiero>A1 . B1</hiero>"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " </td>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\" style=\"width: 22px;\">"
|
||||
, " <tr>"
|
||||
, " <td> "
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Void_full() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str
|
||||
( "<hiero>A1 .. B1</hiero>"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " </td>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\" style=\"width: 44px;\">"
|
||||
, " <tr>"
|
||||
, " <td> "
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void New_line() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str
|
||||
( "<hiero>A1 ! B1</hiero>"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Cartouche() {
|
||||
fxt.Init_hiero_A1_B1().Init_hiero_cartouche();
|
||||
fxt.Test_html_full_str
|
||||
( "<hiero>< A1 ></hiero>"
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Ca1.png' height='44' title='<' alt='<' />"
|
||||
, " </td>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td class='mw-hiero-box' style='height: 2px;'>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td class='mw-hiero-box' style='height: 2px;'>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " <td>"
|
||||
, " <img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Ca2.png' height='44' title='>' alt='>' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Superposition_regular() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str("<hiero>A1:B1</hiero>", String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 20px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' />"
|
||||
, " <br/>"
|
||||
, " <img style='margin: 1px; height: 20px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Superposition_phoneme() {
|
||||
fxt.Init_hiero_p_t();
|
||||
fxt.Test_html_full_str("<hiero>t:p</hiero>", String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 11px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_X1.png' title='X1 [t]' alt='t' />"
|
||||
, " <br/>"
|
||||
, " <img style='margin: 1px; height: 15px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Q3.png' title='Q3 [p]' alt='p' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Superposition_prefab() {
|
||||
fxt.Init_hiero_a_A1();
|
||||
fxt.Test_html_full_str("<hiero>a:A1</hiero>", String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' title='a&A1' alt='a&A1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Juxtaposition_regular() {
|
||||
fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_html_full_str("<hiero>A1*B1</hiero>", String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_A1.png' title='A1' alt='A1' /> "
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_B1.png' title='B1' alt='B1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Juxtaposition_phoneme() {
|
||||
fxt.Init_hiero_p_t();
|
||||
fxt.Test_html_full_str("<hiero>t*p</hiero>", String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 11px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_X1.png' title='X1 [t]' alt='t' /> "
|
||||
, " <img style='margin: 1px; height: 15px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_Q3.png' title='Q3 [p]' alt='p' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Juxtaposition_prefab() {
|
||||
fxt.Init_hiero_a_A1();
|
||||
fxt.Test_html_full_str("<hiero>a*A1</hiero>", String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, " <img style='margin: 1px; height: 38px;' src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' title='a&A1' alt='a&A1' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Para_if_text() {// PURPOSE: check that paras are handled correctly; EX: w:Hieroglyphics; DATE:2014-04-23
|
||||
fxt.Fxt().Init_para_y_();
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( "a" // should always be in <p>
|
||||
, ""
|
||||
, "<hiero></hiero> b" // <hiero> should not be in <p> but "b" should be;
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<p>a"
|
||||
, "</p>"
|
||||
, "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, ""
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
, "<p> b" // NOTE: space seems wrong, but is "harmless"
|
||||
, "</p>"
|
||||
));
|
||||
fxt.Fxt().Init_para_n_();
|
||||
}
|
||||
@Test public void Para_skip_if_list() {// PURPOSE: do not add para if in list; EX:de.d:Damascus; DATE:2014-06-06
|
||||
fxt.Fxt().Init_para_y_();
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( ":<hiero></hiero> a" // a should not be in para
|
||||
, ":b"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<dl>"
|
||||
, " <dd><table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, ""
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, " a"
|
||||
, " </dd>"
|
||||
, " <dd>b"
|
||||
, " </dd>"
|
||||
, "</dl>"
|
||||
));
|
||||
fxt.Fxt().Init_para_n_();
|
||||
}
|
||||
}
|
||||
171
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_wtr.java
Normal file
171
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_html_wtr.java
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
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 = 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();
|
||||
}
|
||||
private static final byte[]
|
||||
Option_bgn_bry = Bry_.new_a7("height: ")
|
||||
, Option_end_bry = Bry_.new_a7("px;")
|
||||
;
|
||||
public void Td(Bry_bfr bfr, byte[] glyph) {
|
||||
bfr.Add(Td_bgn_bry).Add(glyph).Add(Td_end_bry);
|
||||
}
|
||||
private static final byte[]
|
||||
Td_bgn_bry = Bry_.new_a7("\n <td>")
|
||||
, Td_end_bry = Bry_.new_a7("\n </td>")
|
||||
;
|
||||
public void Cartouche_bgn(Bry_bfr bfr) {
|
||||
bfr.Add(Cartouche_bgn_lhs_bry).Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100).Add(Cartouche_bgn_rhs_bry);
|
||||
}
|
||||
private static final String Tbl_bgn_str = "<table class=\"mw-hiero-table\">";
|
||||
private static final byte[]
|
||||
Cartouche_bgn_lhs_bry = Bry_.new_a7(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <td>"
|
||||
, " " + Tbl_bgn_str
|
||||
, " <tr>"
|
||||
, " <td class='mw-hiero-box' style='height: "
|
||||
))
|
||||
, Cartouche_bgn_rhs_bry = Bry_.new_a7(String_.Concat_lines_nl_skip_last
|
||||
( "px;'>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <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);
|
||||
}
|
||||
private static final byte[]
|
||||
Cartouche_end_lhs_bry = Bry_.new_a7(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td class='mw-hiero-box' style='height: "
|
||||
))
|
||||
, Cartouche_end_rhs_bry = Bry_.new_a7(String_.Concat_lines_nl_skip_last
|
||||
( "px;'>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </td>"
|
||||
));
|
||||
public byte[] Cartouche_img(Xoh_wtr_ctx hctx, boolean bgn, byte[] glyph) { // render open / close cartouche; note that MW has two branches, but they are both the same
|
||||
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 ? 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
|
||||
( "\n <img src='~{path}hiero_~{code}.png'"
|
||||
, " height='~{height}' title='~{title}'"
|
||||
, " alt='~{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>';
|
||||
}
|
||||
private static final byte[]
|
||||
Tbl_inner_bgn = Bry_.new_u8(String_.Concat_lines_nl_skip_last
|
||||
( " <table class=\"mw-hiero-table\">"
|
||||
, " <tr>"
|
||||
))
|
||||
, Tbl_inner_end = Bry_.new_u8(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
))
|
||||
;
|
||||
public void Tbl_outer(Bry_bfr bfr, Bry_bfr html_bfr) {
|
||||
bfr.Add(Outer_tbl_bgn);
|
||||
bfr.Add_bfr_and_clear(html_bfr);
|
||||
bfr.Add(Outer_tbl_end);
|
||||
}
|
||||
private static final byte[]
|
||||
Outer_tbl_bgn = Bry_.new_a7(String_.Concat_lines_nl_skip_last
|
||||
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
|
||||
, " <tr>"
|
||||
, " <td>"
|
||||
, ""
|
||||
)
|
||||
)
|
||||
, Outer_tbl_end = Bry_.new_a7(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
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(hctx, img_cls, td_height, glyph_esc, code_esc, 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);
|
||||
}
|
||||
private static final byte[]
|
||||
Tbl_eol_bry = Bry_.new_a7(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " " + 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");
|
||||
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 void_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <table class=\"mw-hiero-table\" style=\"width: ~{width}px;\">"
|
||||
, " <tr>"
|
||||
, " <td> "
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
), "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")
|
||||
;
|
||||
}
|
||||
119
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_mw_tables_parser.java
Normal file
119
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_mw_tables_parser.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.core.log_msgs.*;
|
||||
import gplx.langs.phps.*; import gplx.langs.dsvs.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
public class Hiero_mw_tables_parser {
|
||||
private Php_parser parser = new Php_parser(); private Php_evaluator evaluator;
|
||||
private Php_text_itm_parser quote_parser = new Php_text_itm_parser();
|
||||
public Hiero_mw_tables_parser() {evaluator = new Php_evaluator(Gfo_msg_log.Test());}
|
||||
public void Bld_all(Io_url load_fil, Io_url save_fil) {
|
||||
Hiero_xtn_mgr xtn_mgr = new Hiero_xtn_mgr();
|
||||
xtn_mgr.Clear(); // clear b/c members are actually static; else test will fail
|
||||
Load_data(xtn_mgr, load_fil);
|
||||
Save_data(xtn_mgr, save_fil); // prefabs.gfs (key only); files.gfs (key,size); phonemes (key, val)
|
||||
}
|
||||
public void Load_data(Hiero_xtn_mgr xtn_mgr, Io_url load_fil) {// NOTE: parsing tables.php instead of tables.ser b/c latter is too difficult to read / debug
|
||||
evaluator.Clear();
|
||||
parser.Parse_tkns(Io_mgr.Instance.LoadFilBry(load_fil), evaluator);
|
||||
Php_line[] lines = (Php_line[])evaluator.List().To_ary(Php_line.class);
|
||||
int lines_len = lines.length;
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
Php_line_assign line = (Php_line_assign)lines[i];
|
||||
byte[] key = line.Key().Val_obj_bry();
|
||||
Object o = Tid_hash.Get_by_bry(key);
|
||||
if (o != null) {
|
||||
Byte_obj_val stub = (Byte_obj_val)o;
|
||||
switch (stub.Val()) {
|
||||
case Tid_prefabs: Parse_prefabs(xtn_mgr.Prefab_mgr(), line); break;
|
||||
case Tid_files: Parse_files(xtn_mgr.File_mgr(), line); break;
|
||||
case Tid_phonemes: Parse_phonemes(xtn_mgr.Phoneme_mgr(), line); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Parse_prefabs(Hiero_prefab_mgr mgr, Php_line_assign line) { // $wh_prefabs = array(v, v ...);
|
||||
Php_itm_ary ary = (Php_itm_ary)line.Val();
|
||||
int subs_len = ary.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Php_itm itm = (Php_itm)ary.Subs_get(i);
|
||||
mgr.Add(Php_itm_.Parse_bry(itm));
|
||||
}
|
||||
}
|
||||
private void Parse_files(Hiero_file_mgr mgr, Php_line_assign line) { // $wh_files = array(k => array(w, h), k => array(w, h) ...);
|
||||
Php_itm_ary ary = (Php_itm_ary)line.Val();
|
||||
int subs_len = ary.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Php_itm_kv kv = (Php_itm_kv)ary.Subs_get(i);
|
||||
byte[] key = Php_itm_.Parse_bry(kv.Key());
|
||||
Php_itm_ary val_ary = (Php_itm_ary)kv.Val();
|
||||
int w = Php_itm_.Parse_int_or(val_ary.Subs_get(0), -1);
|
||||
int h = Php_itm_.Parse_int_or(val_ary.Subs_get(1), -1);
|
||||
mgr.Add(key, w, h);
|
||||
}
|
||||
}
|
||||
private void Parse_phonemes(Hiero_phoneme_mgr mgr, Php_line_assign line) { // $wh_phonemes = array(k => v, k => v ...);
|
||||
List_adp tmp_list = List_adp_.New(); Byte_obj_ref tmp_rslt = Byte_obj_ref.zero_(); Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
Php_itm_ary ary = (Php_itm_ary)line.Val();
|
||||
int subs_len = ary.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Php_itm_kv kv = (Php_itm_kv)ary.Subs_get(i);
|
||||
byte[] kv_key = quote_parser.Parse_as_bry(tmp_list, Php_itm_.Parse_bry(kv.Key()), tmp_rslt, tmp_bfr);
|
||||
mgr.Add(kv_key, Php_itm_.Parse_bry(kv.Val()));
|
||||
}
|
||||
}
|
||||
public void Save_data(Hiero_xtn_mgr xtn_mgr, Io_url save_fil) {
|
||||
Xoa_gfs_bldr bldr = new Xoa_gfs_bldr();
|
||||
int len = -1;
|
||||
|
||||
Hiero_prefab_mgr prefab_mgr = xtn_mgr.Prefab_mgr();
|
||||
len = prefab_mgr.Len();
|
||||
bldr.Add_proc_init_many(Hiero_xtn_mgr.Invk_prefabs, Hiero_phoneme_mgr.Invk_srl, Dsv_wkr_base.Invk_load_by_str).Add_quote_xtn_apos_bgn(); // prefabs.srl.load_by_str('\n
|
||||
for (int i = 0; i < len; i++) {
|
||||
Hiero_prefab_itm itm = prefab_mgr.Get_at(i);
|
||||
bldr.Bfr().Add(itm.Key()).Add_byte_nl(); // NOTE: escape not needed
|
||||
}
|
||||
bldr.Add_quote_xtn_apos_end(); // ');\n
|
||||
bldr.Add_nl();
|
||||
|
||||
Hiero_file_mgr file_mgr = xtn_mgr.File_mgr();
|
||||
len = file_mgr.Len();
|
||||
bldr.Add_proc_init_many(Hiero_xtn_mgr.Invk_files, Hiero_phoneme_mgr.Invk_srl, Dsv_wkr_base.Invk_load_by_str).Add_quote_xtn_apos_bgn(); // files.srl.load_by_str('\n
|
||||
for (int i = 0; i < len; i++) {
|
||||
Hiero_file_itm itm = file_mgr.Get_at(i);
|
||||
bldr.Bfr().Add(itm.Key()).Add_byte_pipe().Add_int_variable(itm.File_w()).Add_byte_pipe().Add_int_variable(itm.File_h()).Add_byte_nl(); // NOTE: escape not needed
|
||||
}
|
||||
bldr.Add_quote_xtn_apos_end(); // ');\n
|
||||
bldr.Add_nl();
|
||||
|
||||
Hiero_phoneme_mgr phoneme_mgr = xtn_mgr.Phoneme_mgr();
|
||||
len = phoneme_mgr.Len();
|
||||
bldr.Add_proc_init_many(Hiero_xtn_mgr.Invk_phonemes, Hiero_phoneme_mgr.Invk_srl, Dsv_wkr_base.Invk_load_by_str).Add_paren_bgn().Add_nl(); // phonemes.srl.load_by_str(
|
||||
bldr.Add_quote_xtn_bgn();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Hiero_phoneme_itm itm = phoneme_mgr.Get_at(i);
|
||||
bldr.Bfr().Add(itm.Key()).Add_byte_pipe().Add(itm.Gardiner_code()).Add_byte_nl(); // NOTE: escape not needed
|
||||
}
|
||||
bldr.Add_quote_xtn_end();
|
||||
bldr.Add_paren_end().Add_term_nl();
|
||||
Io_mgr.Instance.SaveFilBfr(save_fil, bldr.Bfr());
|
||||
}
|
||||
private static final byte Tid_prefabs = 0, Tid_files = 1, Tid_phonemes = 2;
|
||||
private static Hash_adp_bry Tid_hash = Hash_adp_bry.cs().Add_str_byte("wh_prefabs", Tid_prefabs).Add_str_byte("wh_files", Tid_files).Add_str_byte("wh_phonemes", Tid_phonemes);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.intls.*;
|
||||
public class Hiero_mw_tables_parser_tst {
|
||||
@Before public void init() {fxt.Reset();} private Hiero_mw_tables_parser_fxt fxt = new Hiero_mw_tables_parser_fxt();
|
||||
@Test public void Basic() {// DATE:2014-04-19
|
||||
fxt.Test_bld_all
|
||||
( String_.Concat_lines_nl_skip_last
|
||||
( "$wh_prefabs = array("
|
||||
, " \"a&A1\","
|
||||
, " \"Z6&A1\","
|
||||
, ");"
|
||||
, ""
|
||||
, "$wh_files = array("
|
||||
, " \"a&A1\" => array( 37, 38 ),"
|
||||
, " \"Z98A\" => array( 5, 15 ),"
|
||||
, ");"
|
||||
, ""
|
||||
, "$wh_phonemes = array("
|
||||
, " \"mSa\" => \"A12\","
|
||||
, " \"\\\"]\" => \"\","
|
||||
, ");"
|
||||
)
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "prefabs.srl.load_by_str('"
|
||||
, "a&A1"
|
||||
, "Z6&A1"
|
||||
, "');"
|
||||
, ""
|
||||
, "files.srl.load_by_str('"
|
||||
, "a&A1|37|38"
|
||||
, "Z98A|5|15"
|
||||
, "');"
|
||||
, ""
|
||||
, "phonemes.srl.load_by_str("
|
||||
, "<:['"
|
||||
, "mSa|A12"
|
||||
, "\"]|"
|
||||
, "']:>"
|
||||
, ");"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Hiero_mw_tables_parser_fxt {
|
||||
private Hiero_mw_tables_parser parser = new Hiero_mw_tables_parser();
|
||||
public void Reset() {}
|
||||
public void Test_bld_all(String raw, String expd) {
|
||||
Io_url load_url = Io_url_.mem_fil_("mem/hiero/load.php");
|
||||
Io_url save_url = Io_url_.mem_fil_("mem/hiero/save.php");
|
||||
Io_mgr.Instance.SaveFilStr(load_url, raw);
|
||||
parser.Bld_all(load_url, save_url);
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(save_url));
|
||||
}
|
||||
public void Exec_bld_all(String load, String save) {
|
||||
parser.Bld_all(Io_url_.new_fil_(load), Io_url_.new_fil_(save));
|
||||
}
|
||||
}
|
||||
133
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_parser.java
Normal file
133
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_parser.java
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.*;
|
||||
class Hiero_parser {
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
private List_adp blocks = List_adp_.New();
|
||||
private Hiero_block cur_block;
|
||||
private Bry_bfr cur_tkn = Bry_bfr_.Reset(16);
|
||||
public Hiero_block[] Parse(byte[] src, int bgn, int end) {
|
||||
blocks.Clear();
|
||||
this.cur_block = new Hiero_block();
|
||||
cur_tkn.Clear();
|
||||
int pos = bgn;
|
||||
while (true) {
|
||||
if (pos == end) break;
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_at_w_b0(trv, b, src, pos, end);
|
||||
if (o == null) {
|
||||
New_char(b);
|
||||
++pos;
|
||||
}
|
||||
else {
|
||||
Hiero_parser_itm itm = (Hiero_parser_itm)o;
|
||||
int new_pos = trv.Pos();
|
||||
switch (itm.Tid()) {
|
||||
case Hiero_parser_itm.Tid_comment:
|
||||
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 + Gfh_tag_.Comm_end_len;
|
||||
break;
|
||||
case Hiero_parser_itm.Tid_block_spr:
|
||||
New_block();
|
||||
break;
|
||||
case Hiero_parser_itm.Tid_single_char:
|
||||
Single_char_block(itm);
|
||||
break;
|
||||
case Hiero_parser_itm.Tid_dot:
|
||||
Dot();
|
||||
break;
|
||||
case Hiero_parser_itm.Tid_tkn_spr:
|
||||
New_token(itm);
|
||||
break;
|
||||
default: throw Err_.new_unhandled(itm.Tid()); // should never happen
|
||||
}
|
||||
pos = new_pos;
|
||||
}
|
||||
}
|
||||
this.New_block();// flush remaining items
|
||||
return (Hiero_block[])blocks.To_ary_and_clear(Hiero_block.class);
|
||||
}
|
||||
private void New_block() {
|
||||
this.New_token(null);
|
||||
if (cur_block.Len() > 0) {
|
||||
blocks.Add(cur_block);
|
||||
cur_block = new Hiero_block();
|
||||
}
|
||||
}
|
||||
private void New_token(Hiero_parser_itm itm) {
|
||||
if (cur_tkn.Len_gt_0())
|
||||
cur_block.Add(cur_tkn.To_bry_and_clear());
|
||||
if (itm != null)
|
||||
cur_block.Add(itm.Key());
|
||||
}
|
||||
private void Single_char_block(Hiero_parser_itm itm) {
|
||||
this.New_block();
|
||||
cur_block.Add(itm.Key());
|
||||
}
|
||||
private void Dot() {
|
||||
if (cur_tkn.Eq(Byte_ascii.Dot)) { // is "."
|
||||
cur_tkn.Add_byte(Byte_ascii.Dot); // make ".."
|
||||
this.New_block();
|
||||
}
|
||||
else {
|
||||
this.New_block();
|
||||
cur_tkn.Add_byte(Byte_ascii.Dot); // make "."; note that New_block clears tkn
|
||||
}
|
||||
}
|
||||
private void New_char(byte b) {
|
||||
if (b == Byte_ascii.Dot) { // is "."; NOTE: never occurs; should always hit dot block; transcribed literally from MW
|
||||
this.New_block();
|
||||
this.cur_tkn.Add_byte(b); // $this->token = $char;
|
||||
}
|
||||
else
|
||||
this.cur_tkn.Add_byte(b); // $this->token .= $char;
|
||||
}
|
||||
public void Init() {
|
||||
Init_itms(Hiero_parser_itm.Tid_block_spr, " ", "-", "\t", "\n", "\r");
|
||||
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, Gfh_tag_.Comm_bgn_str);
|
||||
}
|
||||
private void Init_itms(byte tid, String... keys) {
|
||||
int keys_len = keys.length;
|
||||
for (int i = 0; i < keys_len; i++) {
|
||||
String key_str = keys[i];
|
||||
byte[] key_bry = Bry_.new_u8(key_str);
|
||||
Hiero_parser_itm itm = new Hiero_parser_itm(tid, key_bry);
|
||||
trie.Add_obj(key_bry, itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Hiero_parser_itm {
|
||||
public Hiero_parser_itm(byte tid, byte[] key) {this.tid = tid; this.key = key;}
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public static final byte Tid_block_spr = 1, Tid_tkn_spr = 2, Tid_single_char = 3, Tid_dot = 4, Tid_comment = 5;
|
||||
}
|
||||
class Hiero_block {
|
||||
private List_adp list = List_adp_.New();
|
||||
public int Len() {return list.Count();}
|
||||
public byte[] Get_at(int i) {return (byte[])list.Get_at(i);}
|
||||
public void Add(byte[] v) {list.Add(v);}
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_parser_tst.java
Normal file
59
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_parser_tst.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Hiero_parser_tst {
|
||||
@Before public void init() {fxt.Reset();} private Hiero_parser_fxt fxt = new Hiero_parser_fxt();
|
||||
@Test public void Separator() {
|
||||
String[][] expd = new String[][] {fxt.block_("A1"), fxt.block_("B1")};
|
||||
fxt.Test_parse("A1 B1" , expd); // space
|
||||
fxt.Test_parse("A1-B1" , expd); // dash
|
||||
fxt.Test_parse("A1\tB1" , expd); // tab
|
||||
fxt.Test_parse("A1\nB1" , expd); // nl
|
||||
fxt.Test_parse("A1\rB1" , expd); // cr
|
||||
fxt.Test_parse("A1 B1" , expd); // many: space
|
||||
fxt.Test_parse("A1 \t\nB1" , expd); // many: mixed
|
||||
}
|
||||
}
|
||||
class Hiero_parser_fxt {
|
||||
private Hiero_parser parser;
|
||||
public void Reset() {
|
||||
parser = new Hiero_parser();
|
||||
parser.Init();
|
||||
}
|
||||
public String[] block_(String... v) {return v;}
|
||||
public void Test_parse(String raw, String[]... expd) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Hiero_block[] actl = parser.Parse(raw_bry, 0, raw_bry.length);
|
||||
Tfds.Eq_ary(String_.Ary_flatten(expd), String_.Ary_flatten(Xto_str(actl)));
|
||||
}
|
||||
private String[][] Xto_str(Hiero_block[] ary) {
|
||||
int len = ary.length;
|
||||
String[][] rv = new String[len][];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Hiero_block itm = ary[i];
|
||||
int itm_len = itm.Len();
|
||||
String[] rv_sub = new String[itm_len];
|
||||
rv[i] = rv_sub;
|
||||
for (int j = 0; j < itm_len; j++) {
|
||||
rv_sub[j] = String_.new_u8(itm.Get_at(j));
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_phoneme_mgr.java
Normal file
59
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_phoneme_mgr.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.dsvs.*;
|
||||
class Hiero_phoneme_mgr implements Gfo_invk {
|
||||
private Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
private Hiero_phoneme_srl srl;
|
||||
public Hiero_phoneme_mgr() {srl = new Hiero_phoneme_srl(this);}
|
||||
public int Len() {return hash.Count();}
|
||||
public Hiero_phoneme_itm Get_at(int i) {return (Hiero_phoneme_itm)hash.Get_at(i);}
|
||||
public void Add(byte[] key, byte[] val) {hash.Add(key, new Hiero_phoneme_itm(key, val));}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Hiero_phoneme_itm Get_by_key(byte[] key) {return (Hiero_phoneme_itm)hash.Get_by(key);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_srl)) return srl;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
}
|
||||
public static final String Invk_srl = "srl";
|
||||
}
|
||||
class Hiero_phoneme_itm {
|
||||
public Hiero_phoneme_itm(byte[] key, byte[] gardiner_code) {this.key = key; this.gardiner_code = gardiner_code;}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public byte[] Gardiner_code() {return gardiner_code;} private byte[] gardiner_code;
|
||||
}
|
||||
class Hiero_phoneme_srl extends Dsv_wkr_base {
|
||||
private Hiero_phoneme_mgr mgr;
|
||||
private byte[] key;
|
||||
private byte[] val;
|
||||
public Hiero_phoneme_srl(Hiero_phoneme_mgr mgr) {this.mgr = mgr;}
|
||||
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser};}
|
||||
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
|
||||
switch (fld_idx) {
|
||||
case 0: key = Bry_.Mid(src, bgn, end); return true;
|
||||
case 1: val = Bry_.Mid(src, bgn, end); return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
|
||||
if (key == null) throw parser.Err_row_bgn("phoneme missing key", pos);
|
||||
if (val == null) throw parser.Err_row_bgn("phoneme missing val", pos);
|
||||
mgr.Add(key, val);
|
||||
key = val = null;
|
||||
}
|
||||
}
|
||||
53
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_prefab_mgr.java
Normal file
53
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_prefab_mgr.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.dsvs.*;
|
||||
class Hiero_prefab_mgr implements Gfo_invk {
|
||||
private Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
private Hiero_prefab_srl srl;
|
||||
public Hiero_prefab_mgr() {srl = new Hiero_prefab_srl(this);}
|
||||
public int Len() {return hash.Count();}
|
||||
public Hiero_prefab_itm Get_at(int i) {return (Hiero_prefab_itm)hash.Get_at(i);}
|
||||
public Hiero_prefab_itm Get_by_key(byte[] key) {return (Hiero_prefab_itm)hash.Get_by(key);}
|
||||
public void Add(byte[] key) {hash.Add(key, new Hiero_prefab_itm(key));}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_srl)) return srl;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_srl = "srl";
|
||||
}
|
||||
class Hiero_prefab_itm {
|
||||
public Hiero_prefab_itm(byte[] key) {this.key = key;}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
}
|
||||
class Hiero_prefab_srl extends Dsv_wkr_base {
|
||||
private Hiero_prefab_mgr mgr;
|
||||
private byte[] key;
|
||||
public Hiero_prefab_srl(Hiero_prefab_mgr mgr) {this.mgr = mgr;}
|
||||
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Bry_parser};}
|
||||
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
|
||||
switch (fld_idx) {
|
||||
case 0: key = Bry_.Mid(src, bgn, end); return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
|
||||
if (key == null) throw parser.Err_row_bgn("prefab missing key", pos);
|
||||
mgr.Add(key);
|
||||
}
|
||||
}
|
||||
45
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xnde.java
Normal file
45
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xnde.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Hiero_xnde implements Xox_xnde {
|
||||
private Hiero_xtn_mgr xtn_mgr;
|
||||
private Hiero_block[] blocks;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
xtn_mgr = (Hiero_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Hiero_xtn_mgr.Xtn_key_static);
|
||||
xtn_mgr.Xtn_init_assert(wiki);
|
||||
ctx.Page().Html_data().Head_mgr().Itm__hiero().Enabled_y_();
|
||||
blocks = xtn_mgr.Parser().Parse(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Page(), Xop_log_basic_wkr.Tid_hiero, src, xnde);
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
switch (ctx.Cur_tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_list: // NOTE: if inside list, do not reenable para mode; questionable logic; PAGE:de.d:Damascus;DATE:2014-06-06
|
||||
break;
|
||||
default:
|
||||
ctx.Para().Process_nl(ctx, root, src, xnde.Tag_close_end(), xnde.Tag_close_end()); // NOTE: this should create an extra stub "p" so that remaining text gets enclosed in <p>; EX:w:Hieroglyphics;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
|
||||
xtn_mgr.Html_wtr().Render_blocks(bfr, hctx, blocks, Hiero_html_mgr.scale, false);
|
||||
}
|
||||
}
|
||||
57
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java
Normal file
57
400_xowa/src/gplx/xowa/xtns/hieros/Hiero_xtn_mgr.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.htmls.modules.*; import gplx.xowa.apps.fsys.*;
|
||||
public class Hiero_xtn_mgr extends Xox_mgr_base implements Gfo_invk {
|
||||
@Override public boolean Enabled_default() {return true;}
|
||||
@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 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();
|
||||
xtn_init_done = true;
|
||||
}
|
||||
@gplx.Internal protected Hiero_parser Parser() {return parser;} private static final Hiero_parser parser = new Hiero_parser();
|
||||
@gplx.Internal protected Hiero_prefab_mgr Prefab_mgr() {return prefab_mgr;} private static final Hiero_prefab_mgr prefab_mgr = new Hiero_prefab_mgr();
|
||||
@gplx.Internal protected Hiero_file_mgr File_mgr() {return file_mgr;} private static final Hiero_file_mgr file_mgr = new Hiero_file_mgr();
|
||||
@gplx.Internal protected Hiero_phoneme_mgr Phoneme_mgr() {return phoneme_mgr;} private static final Hiero_phoneme_mgr phoneme_mgr = new Hiero_phoneme_mgr();
|
||||
@gplx.Internal protected Hiero_html_mgr Html_wtr() {return html_wtr;} private static Hiero_html_mgr html_wtr;
|
||||
public void Clear() {
|
||||
prefab_mgr.Clear();
|
||||
file_mgr.Clear();
|
||||
phoneme_mgr.Clear();
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_prefabs)) return prefab_mgr;
|
||||
else if (ctx.Match(k, Invk_files)) return file_mgr;
|
||||
else if (ctx.Match(k, Invk_phonemes)) return phoneme_mgr;
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
}
|
||||
public static final String Invk_prefabs = "prefabs", Invk_files = "files", Invk_phonemes = "phonemes";
|
||||
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;}
|
||||
}
|
||||
Reference in New Issue
Block a user