mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
71
400_xowa/src/gplx/xowa/xtns/imaps/Imap_desc_tid.java
Normal file
71
400_xowa/src/gplx/xowa/xtns/imaps/Imap_desc_tid.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
class Imap_desc_tid {
|
||||
public static final byte Tid_tr = 0, Tid_br = 1, Tid_bl = 2, Tid_tl = 3, Tid_none = 4, Tid_null = 5;
|
||||
public static final byte[]
|
||||
Key_tr = Bry_.new_a7("top-right")
|
||||
, Key_br = Bry_.new_a7("bottom-right")
|
||||
, Key_bl = Bry_.new_a7("bottom-left")
|
||||
, Key_tl = Bry_.new_a7("top-left")
|
||||
, Key_none = Bry_.new_a7("none")
|
||||
;
|
||||
public static Btrie_slim_mgr trie_(Xowe_wiki wiki) {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_utf_8_();
|
||||
trie_add(rv, Key_tr, Key_br, Key_bl, Key_tl, Key_none);
|
||||
byte[][] lang_types = Parse_lang_types(wiki);
|
||||
if (lang_types != null)
|
||||
trie_add(rv, lang_types);
|
||||
return rv;
|
||||
}
|
||||
private static void trie_add(Btrie_slim_mgr trie, byte[]... ary) {
|
||||
trie.Add_bry_bval(ary[0] ,Tid_tr);
|
||||
trie.Add_bry_bval(ary[1] ,Tid_br);
|
||||
trie.Add_bry_bval(ary[2] ,Tid_bl);
|
||||
trie.Add_bry_bval(ary[3] ,Tid_tl);
|
||||
trie.Add_bry_bval(ary[4] ,Tid_none);
|
||||
}
|
||||
private static byte[][] Parse_lang_types(Xowe_wiki wiki) {
|
||||
byte[] val = wiki.Msg_mgr().Val_by_key_obj("imagemap_desc_types");
|
||||
if (Bry_.Len_eq_0(val)) return null; // no msg in lang; return;
|
||||
byte[][] ary = Bry_.Split(val, Byte_ascii.Comma); // msg is 5 words concatenated by comma: EX:top-right,bottom-right-bottom-left,top-left,none
|
||||
int ary_len = ary.length;
|
||||
if (ary_len != 5) wiki.Appe().Usr_dlg().Warn_many("", "", "imap_desc does not have 5 items; wiki=~{0} val=~{1}", wiki.Domain_bry(), val);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
ary[i] = Bry_.Trim(ary[i]); // note that items will have trailing ws; EX: "top-right, bottom-right, bottom-left, top-left, none"
|
||||
return ary;
|
||||
}
|
||||
public static byte parse_(Btrie_slim_mgr trie, byte[] src, int bgn, int end) {
|
||||
Object rv = trie.Match_bgn(src, bgn, end);
|
||||
return rv == null ? Tid_null : ((Byte_obj_val)rv).Val();
|
||||
}
|
||||
public static void Calc_desc_margins(Int_2_ref rv, byte tid, int html_w, int html_h) {
|
||||
int margin_l
|
||||
= tid == Tid_tl || tid == Tid_bl
|
||||
? 0
|
||||
: html_w - 20
|
||||
;
|
||||
int margin_t
|
||||
= tid == Tid_tl || tid == Tid_tr
|
||||
? -html_h + 1 // 1px hack for IE, to stop it poking out the top
|
||||
: -20
|
||||
;
|
||||
rv.Val_all_(margin_l, margin_t);
|
||||
}
|
||||
}
|
||||
65
400_xowa/src/gplx/xowa/xtns/imaps/Imap_html_fmtrs.java
Normal file
65
400_xowa/src/gplx/xowa/xtns/imaps/Imap_html_fmtrs.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
class Imap_html_fmtrs {
|
||||
public static final Bry_fmtr
|
||||
All = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div id='imap_div_~{imap_id}' class=\"noresize\"~{desc_style}>~{map}~{img}"
|
||||
, " </div>"
|
||||
), "imap_id", "desc_style", "map", "img"
|
||||
)
|
||||
, Map = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <map name=\"imageMap_1_~{imap_id}\">~{shapes}"
|
||||
, " </map>"
|
||||
), "imap_id", "shapes"
|
||||
)
|
||||
, Area = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "\n <area href=\"~{href}\" shape=\"~{shape}\" coords=\"~{coords}\" alt=\"~{title}\" title=\"~{title}\"/>"
|
||||
), "href", "shape", "coords", "title")
|
||||
, Img_anchor_none = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\"~{img_core}~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
|
||||
), "imap_id", "img_elem_id", "img_alt", "img_core", "img_cls", "anchor_href", "anchor_title"
|
||||
)
|
||||
, Img_anchor_lnki = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <a href=\"~{anchor_href}\" title=\"~{anchor_title}\">"
|
||||
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\"~{img_core}~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
|
||||
, " </a>"
|
||||
), "imap_id", "img_elem_id", "img_alt", "img_core", "img_cls", "anchor_href", "anchor_title"
|
||||
)
|
||||
, Img_anchor_lnke = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <a href=\"~{anchor_href}\" title=~{anchor_title} class=\"plainlinks\" rel=\"nofollow\">"
|
||||
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\"~{img_core}~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
|
||||
, " </a>"
|
||||
), "imap_id", "img_elem_id", "img_alt", "img_core", "img_cls", "anchor_href", "anchor_title"
|
||||
)
|
||||
, Desc_style = Bry_fmtr.new_(" style=\"height:~{div_h}px; width: ~{div_w}px;\"", "div_w", "div_h")
|
||||
, Desc_main = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div style=\"margin-left:~{margin_left}px; margin-top:~{margin_top}px; text-align:left;\">"
|
||||
, " <a href=\"~{img_href}\" title=\"~{msg_desc}\">"
|
||||
, " <img alt=\"~{msg_desc}\" src=\"~{icon_url}\" style=\"border: none;\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "margin_left", "margin_top", "img_href", "msg_desc", "icon_url"
|
||||
)
|
||||
;
|
||||
}
|
||||
52
400_xowa/src/gplx/xowa/xtns/imaps/Imap_img_fmtr_arg.java
Normal file
52
400_xowa/src/gplx/xowa/xtns/imaps/Imap_img_fmtr_arg.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
|
||||
class Imap_img_fmtr_arg implements Bry_fmtr_arg {
|
||||
private Xoh_wtr_ctx hctx; private Imap_map map; private Imap_xtn_mgr xtn_mgr;
|
||||
private int img_elem_id, img_w, img_h;
|
||||
private byte[] img_alt, img_src, img_cls, img_href;
|
||||
private Int_2_ref margin_calc = new Int_2_ref();
|
||||
public void Init(Xoh_wtr_ctx hctx, Imap_xtn_mgr xtn_mgr, Imap_map map, int img_elem_id, byte[] img_alt, byte[] img_src, int img_w, int img_h, byte[] img_cls, byte[] img_href) {
|
||||
this.hctx = hctx; this.map = map; this.xtn_mgr = xtn_mgr;
|
||||
this.img_elem_id = img_elem_id; this.img_w = img_w; this.img_h = img_h;
|
||||
this.img_alt = img_alt;
|
||||
this.img_src = img_src;
|
||||
this.img_cls = img_cls;
|
||||
this.img_href = img_href;
|
||||
}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
Bry_fmtr fmtr = Imap_html_fmtrs.Img_anchor_none;
|
||||
byte[] anchor_href = Bry_.Empty, anchor_text = Bry_.Empty;
|
||||
Imap_itm_dflt itm_dflt = map.Dflt();
|
||||
boolean hctx_is_hdump = hctx.Mode_is_hdump();
|
||||
Xoh_arg_img_core img_core_fmtr = xtn_mgr.Img_core_fmtr(hctx_is_hdump);
|
||||
img_core_fmtr.Init(img_elem_id, img_src, img_w, img_h);
|
||||
if (itm_dflt != null) {
|
||||
fmtr = itm_dflt.Link_tid() == Xop_tkn_itm_.Tid_lnki ? Imap_html_fmtrs.Img_anchor_lnki : Imap_html_fmtrs.Img_anchor_lnke;
|
||||
anchor_href = itm_dflt.Link_href();
|
||||
anchor_text = itm_dflt.Link_text();
|
||||
}
|
||||
fmtr.Bld_bfr_many(bfr, map.Id(), img_elem_id, img_alt, img_core_fmtr, img_cls, anchor_href, anchor_text);
|
||||
Imap_itm_desc itm_desc = map.Desc();
|
||||
if (itm_desc != null) {
|
||||
Imap_desc_tid.Calc_desc_margins(margin_calc, itm_desc.Desc_tid(), img_w, img_h);
|
||||
Imap_html_fmtrs.Desc_main.Bld_bfr_many(bfr, margin_calc.Val_0(), margin_calc.Val_1(), img_href, xtn_mgr.Desc_msg(), xtn_mgr.Desc_icon_url());
|
||||
}
|
||||
}
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/xtns/imaps/Imap_itm.java
Normal file
59
400_xowa/src/gplx/xowa/xtns/imaps/Imap_itm.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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
interface Imap_itm {
|
||||
byte Itm_tid();
|
||||
}
|
||||
class Imap_itm_ {
|
||||
public static final byte Tid_invalid = 0, Tid_img = 1, Tid_desc = 2, Tid_comment = 3, Tid_dflt = 4, Tid_shape_rect = 5, Tid_shape_circle = 6, Tid_shape_poly = 7;
|
||||
public static final byte[]
|
||||
Key_dflt = Bry_.new_a7("default")
|
||||
, Key_shape_rect = Bry_.new_a7("rect")
|
||||
, Key_shape_circle = Bry_.new_a7("circle")
|
||||
, Key_shape_poly = Bry_.new_a7("poly")
|
||||
;
|
||||
public static byte[] Xto_key(byte v) {
|
||||
switch (v) {
|
||||
case Tid_shape_rect : return Key_shape_rect;
|
||||
case Tid_shape_circle : return Key_shape_circle;
|
||||
case Tid_shape_poly : return Key_shape_poly;
|
||||
default : throw Exc_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Imap_itm_img implements Imap_itm {
|
||||
public Imap_itm_img(Xop_lnki_tkn img_link) {this.img_link = img_link;}
|
||||
public byte Itm_tid() {return Imap_itm_.Tid_img;}
|
||||
public Xop_lnki_tkn Img_link() {return img_link;} private Xop_lnki_tkn img_link;
|
||||
}
|
||||
class Imap_itm_desc implements Imap_itm {
|
||||
public Imap_itm_desc(byte desc_tid) {this.desc_tid = desc_tid;}
|
||||
public byte Itm_tid() {return Imap_itm_.Tid_desc;}
|
||||
public byte Desc_tid() {return desc_tid;} private byte desc_tid;
|
||||
}
|
||||
class Imap_itm_dflt implements Imap_itm, Imap_link_owner {
|
||||
public byte Itm_tid() {return Imap_itm_.Tid_dflt;}
|
||||
public int Link_tid() {return link_tid;} public void Link_tid_(int v) {link_tid = v;} private int link_tid;
|
||||
public byte[] Link_href() {return link_href;} public void Link_href_(byte[] v) {this.link_href = v;} private byte[] link_href;
|
||||
public byte[] Link_text() {return link_text;} public void Link_text_(byte[] v) {this.link_text = v;} private byte[] link_text;
|
||||
}
|
||||
class Imap_err {
|
||||
public Imap_err(int itm_idx, String err_key) {this.itm_idx = itm_idx; this.err_key = err_key;}
|
||||
public int Itm_idx() {return itm_idx;} private int itm_idx;
|
||||
public String Err_key() {return err_key;} private String err_key;
|
||||
}
|
||||
67
400_xowa/src/gplx/xowa/xtns/imaps/Imap_itm_shape.java
Normal file
67
400_xowa/src/gplx/xowa/xtns/imaps/Imap_itm_shape.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.parsers.lnkes.*; import gplx.xowa.html.*; import gplx.xowa.net.*;
|
||||
interface Imap_link_owner {
|
||||
void Link_tid_(int v);
|
||||
void Link_href_(byte[] v);
|
||||
void Link_text_(byte[] v);
|
||||
}
|
||||
class Imap_link_owner_ {
|
||||
public static void Init(Imap_link_owner link_owner, Xoae_app app, Xowe_wiki wiki, byte[] src, Xop_tkn_itm tkn) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
int tkn_tid = tkn.Tkn_tid();
|
||||
link_owner.Link_tid_(tkn_tid);
|
||||
switch (tkn_tid) {
|
||||
case Xop_tkn_itm_.Tid_lnki: {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn;
|
||||
link_owner.Link_href_(app.Href_parser().Build_to_bry(wiki, lnki_tkn.Ttl()));
|
||||
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_caption(bfr, Xoh_wtr_ctx.Alt, src, lnki_tkn, lnki_tkn.Ttl());
|
||||
link_owner.Link_text_(bfr.Xto_bry_and_clear());
|
||||
break;
|
||||
}
|
||||
case Xop_tkn_itm_.Tid_lnke: {
|
||||
Xop_lnke_tkn lnke = (Xop_lnke_tkn)tkn;
|
||||
Xop_ctx ctx = wiki.Ctx();
|
||||
int lnke_bgn = lnke.Lnke_bgn(), lnke_end = lnke.Lnke_end(); boolean proto_is_xowa = lnke.Proto_tid() == Xoo_protocol_itm.Tid_xowa;
|
||||
Xoh_lnke_wtr lnke_wtr = wiki.Html_mgr().Html_wtr().Lnke_wtr();
|
||||
lnke_wtr.Write_href(bfr, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_href_(bfr.Xto_bry_and_clear());
|
||||
lnke_wtr.Write_caption(bfr, wiki.Html_mgr().Html_wtr(), Xoh_wtr_ctx.Basic, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_text_(bfr.Xto_bry_and_clear());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {bfr.Mkr_rls();} // release buffer in case of null error; PAGE:de.u:PPA/Raster/TK25/51/18/12/20; DATE:2015-02-02
|
||||
}
|
||||
}
|
||||
class Imap_itm_shape implements Imap_itm, Imap_link_owner {
|
||||
public Imap_itm_shape(byte shape_tid, Double_obj_val[] shape_pts) {
|
||||
this.shape_tid = shape_tid;
|
||||
this.shape_pts = shape_pts;
|
||||
}
|
||||
public byte Itm_tid() {return shape_tid;} private byte shape_tid;
|
||||
public Double_obj_val[] Shape_pts() {return shape_pts;} private Double_obj_val[] shape_pts;
|
||||
public int Link_tid() {return link_tid;} public void Link_tid_(int v) {link_tid = v;} private int link_tid;
|
||||
public byte[] Link_href() {return link_href;} public void Link_href_(byte[] v) {this.link_href = v;} private byte[] link_href;
|
||||
public byte[] Link_text() {return link_text;} public void Link_text_(byte[] v) {this.link_text = v;} private byte[] link_text;
|
||||
public static final byte Tid_default = 0, Tid_rect = 4, Tid_circle = 3, Tid_poly = 5;
|
||||
}
|
||||
73
400_xowa/src/gplx/xowa/xtns/imaps/Imap_map.java
Normal file
73
400_xowa/src/gplx/xowa/xtns/imaps/Imap_map.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.html.*; import gplx.xowa.files.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.html.lnkis.*;
|
||||
import gplx.xowa.html.hdumps.core.*;
|
||||
public class Imap_map implements Xoh_file_img_wkr, Js_img_wkr {
|
||||
private static final Imap_map_fmtr map_fmtr_arg = new Imap_map_fmtr();
|
||||
public Imap_map(int id) {this.id = id;}
|
||||
public Imap_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Imap_xtn_mgr xtn_mgr;
|
||||
@gplx.Internal protected void Init(Imap_xtn_mgr xtn_mgr, byte[] img_src, Imap_itm_img img, Imap_itm_dflt dflt, Imap_itm_desc desc, Imap_itm_shape[] shapes, Imap_err[] errs) {
|
||||
this.xtn_mgr = xtn_mgr; this.img_src = img_src; this.img = img; this.dflt = dflt; this.desc = desc; this.shapes = shapes; this.errs = errs;
|
||||
}
|
||||
public boolean Invalid() {return img == null;} // invalid if missing image; PAGE:en.w:Wikipedia:WikiProject_Games/Advert EX: <imagemap>|thumb;</imagemap>; DATE:2014-08-12
|
||||
public int Id() {return id;} private int id;
|
||||
public byte[] Img_src() {return img_src;} private byte[] img_src;
|
||||
@gplx.Internal protected Imap_itm_img Img() {return img;} private Imap_itm_img img;
|
||||
@gplx.Internal protected Imap_itm_dflt Dflt() {return dflt;} private Imap_itm_dflt dflt;
|
||||
@gplx.Internal protected Imap_itm_desc Desc() {return desc;} private Imap_itm_desc desc;
|
||||
@gplx.Internal protected Imap_itm_shape[] Shapes() {return shapes;} private Imap_itm_shape[] shapes;
|
||||
@gplx.Internal protected Imap_err[] Errs() {return errs;} private Imap_err[] errs;
|
||||
private byte img_cls_tid;
|
||||
private byte[] a_href, img_alt, img_cls_other;
|
||||
public void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoae_page page, Xof_file_itm xfer_itm, int uid
|
||||
, byte[] a_href, byte a_cls, byte a_rel, byte[] a_title, byte[] a_xowa_title
|
||||
, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte img_cls, byte[] img_cls_other
|
||||
) {
|
||||
xfer_itm.Html_img_wkr_(this);
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_imap);
|
||||
this.a_href = a_href; this.img_alt = img_alt; this.img_cls_tid = img_cls; this.img_cls_other = img_cls_other;
|
||||
Write_imap_div(tmp_bfr, hctx, uid, img_w, img_h, img_src, xfer_itm.Orig_w(), xfer_itm.Orig_h());
|
||||
if (hctx.Mode_is_hdump())
|
||||
page.Hdump_data().Imgs_add_img(new Xohd_data_itm__img(), xfer_itm, Xohd_data_itm__gallery_itm.Tid_basic);
|
||||
}
|
||||
public void Html_update(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Io_url html_orig_url, byte[] lnki_ttl) {
|
||||
Xowe_wiki wiki = xtn_mgr.Wiki();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
Write_imap_div(tmp_bfr, Xoh_wtr_ctx.Basic, html_uid, html_w, html_h, html_view_url.To_http_file_bry(), orig_w, orig_h);
|
||||
js_wkr.Html_elem_replace_html("imap_div_" + Int_.Xto_str(html_uid), tmp_bfr.To_str_and_rls());
|
||||
}
|
||||
private void Write_imap_div(Bry_bfr bfr, Xoh_wtr_ctx hctx, int html_uid, int html_w, int html_h, byte[] html_src, int orig_w, int orig_h) {
|
||||
byte[] desc_style = Calc_desc_style(html_w, html_h);
|
||||
map_fmtr_arg.Init(id, shapes, Calc_scale(orig_w, orig_h, html_w, html_h));
|
||||
img_fmtr_arg.Init(hctx, xtn_mgr, this, html_uid, img_alt, html_src, html_w, html_h, Xoh_lnki_consts.Img_cls_to_bry(img_cls_tid, img_cls_other), a_href);
|
||||
Imap_html_fmtrs.All.Bld_bfr_many(bfr, html_uid, desc_style, map_fmtr_arg, img_fmtr_arg);
|
||||
}
|
||||
private byte[] Calc_desc_style(int html_w, int html_h) {
|
||||
if (desc == null) return Bry_.Empty;
|
||||
Bry_bfr tmp_bfr = xtn_mgr.Wiki().Utl__bfr_mkr().Get_b128().Mkr_rls();
|
||||
return Imap_html_fmtrs.Desc_style.Bld_bry_many(tmp_bfr, html_w, html_h);
|
||||
}
|
||||
private static final Imap_img_fmtr_arg img_fmtr_arg = new Imap_img_fmtr_arg();
|
||||
private static double Calc_scale(int orig_w, int orig_h, int html_w, int html_h) {
|
||||
int denominator = orig_w + orig_h;
|
||||
int numerator = html_w + html_h;
|
||||
if (denominator <= 0 || numerator <= 0) return 1; // return identity; note that MW does "return self::error( 'imagemap_invalid_image' );"
|
||||
return (double)numerator / (double)denominator;
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/xtns/imaps/Imap_map_fmtr.java
Normal file
50
400_xowa/src/gplx/xowa/xtns/imaps/Imap_map_fmtr.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
class Imap_map_fmtr implements Bry_fmtr_arg {
|
||||
private int imap_id;
|
||||
public void Init(int imap_id, Imap_itm_shape[] shapes, double scale) {this.imap_id = imap_id; shapes_fmtr_arg.Init(shapes, scale);}
|
||||
public Imap_pts_fmtr_arg Pts_fmtr() {return shapes_fmtr_arg.Pts_fmtr();}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
Imap_html_fmtrs.Map.Bld_bfr_many(bfr, imap_id, shapes_fmtr_arg);
|
||||
}
|
||||
private static final Imap_shapes_fmtr shapes_fmtr_arg = new Imap_shapes_fmtr();
|
||||
}
|
||||
class Imap_shapes_fmtr implements Bry_fmtr_arg {
|
||||
private Imap_itm_shape[] shapes;
|
||||
public void Init(Imap_itm_shape[] shapes, double scale) {this.shapes = shapes; pts_fmtr_arg.Scale_(scale);}
|
||||
public Imap_pts_fmtr_arg Pts_fmtr() {return pts_fmtr_arg;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
int shapes_len = shapes.length;
|
||||
Bry_fmtr fmtr = Imap_html_fmtrs.Area;
|
||||
for (int i = 0; i < shapes_len; ++i) {
|
||||
Imap_itm_shape shape = shapes[i];
|
||||
Fmt_shape(bfr, fmtr, pts_fmtr_arg, shape);
|
||||
}
|
||||
}
|
||||
@gplx.Internal protected static void Fmt_shape(Bry_bfr bfr, Bry_fmtr fmtr, Imap_pts_fmtr_arg pts_fmtr, Imap_itm_shape shape) {
|
||||
pts_fmtr_arg.Pts_(shape.Shape_pts());
|
||||
fmtr.Bld_bfr_many(bfr
|
||||
, shape.Link_href()
|
||||
, Imap_itm_.Xto_key(shape.Itm_tid())
|
||||
, pts_fmtr_arg
|
||||
, shape.Link_text()
|
||||
);
|
||||
}
|
||||
private static final Imap_pts_fmtr_arg pts_fmtr_arg = new Imap_pts_fmtr_arg();
|
||||
}
|
||||
234
400_xowa/src/gplx/xowa/xtns/imaps/Imap_parser.java
Normal file
234
400_xowa/src/gplx/xowa/xtns/imaps/Imap_parser.java
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*; import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
class Imap_parser {
|
||||
private Imap_xtn_mgr xtn_mgr; private Xoa_url page_url; private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.I;
|
||||
private byte[] imap_img_src;
|
||||
private Imap_itm_img imap_img;
|
||||
private Imap_itm_dflt imap_dflt;
|
||||
private Imap_itm_desc imap_desc;
|
||||
private List_adp shapes = List_adp_.new_(), pts = List_adp_.new_(), errs = List_adp_.new_();
|
||||
private byte[] src;
|
||||
private int itm_idx; private int itm_bgn, itm_end;
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xop_ctx wiki_ctx, imap_ctx; private Xop_root_tkn imap_root;
|
||||
public Imap_parser(Imap_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
|
||||
public void Init(Xowe_wiki wiki, Xoa_url page_url, Gfo_usr_dlg usr_dlg) {
|
||||
this.app = wiki.Appe(); this.wiki = wiki; this.page_url = page_url; this.usr_dlg = usr_dlg;
|
||||
this.wiki_ctx = wiki.Ctx();
|
||||
if (imap_ctx == null) {
|
||||
imap_ctx = Xop_ctx.new_(wiki);
|
||||
imap_root = app.Tkn_mkr().Root(Bry_.Empty);
|
||||
}
|
||||
}
|
||||
public void Clear() {
|
||||
this.itm_idx = 0;
|
||||
imap_img = null; imap_img_src = null; imap_desc = null; imap_dflt = null;
|
||||
shapes.Clear(); pts.Clear(); errs.Clear();
|
||||
}
|
||||
public Imap_map Parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
Imap_map rv = new Imap_map(ctx.Cur_page().Html_data().Xtn_imap_next_id());
|
||||
Init(wiki, ctx.Cur_page().Url(), wiki.Appe().Usr_dlg());
|
||||
this.Parse(rv, src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
return rv;
|
||||
}
|
||||
public void Parse(Imap_map rv, byte[] src, int src_bgn, int src_end) {
|
||||
this.Clear();
|
||||
this.src = src;
|
||||
itm_bgn = src_bgn; itm_end = src_bgn - 1;
|
||||
while (true) {
|
||||
if (itm_end == src_end) break;
|
||||
itm_bgn = Bry_finder.Trim_fwd_space_tab(src, itm_end + 1, src_end); // trim ws at start, and look for first char
|
||||
if (itm_bgn == src_end) break; // line is entirely ws and terminated by eos; EX: "\n EOS"
|
||||
itm_end = Bry_finder.Find_fwd_until(src, itm_bgn, src_end, Byte_ascii.Nl); // look for \n
|
||||
if (itm_end == Bry_finder.Not_found) itm_end = src_end; // no \n; make EOS = \n
|
||||
itm_end = Bry_finder.Trim_bwd_space_tab(src, itm_end, itm_bgn); // trim any ws at end
|
||||
if (itm_end - itm_bgn == 0) continue; // line is entirely ws; continue;
|
||||
byte b = src[itm_bgn];
|
||||
if (b == Byte_ascii.Hash) {
|
||||
Parse_comment(itm_bgn, itm_end);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (itm_idx == 0)
|
||||
itm_end = Parse_img(rv, itm_bgn, itm_end, src_end);
|
||||
else {
|
||||
Object tid_obj = tid_trie.Match_bgn_w_byte(b, src, itm_bgn, itm_end);
|
||||
byte tid_val = tid_obj == null ? Imap_itm_.Tid_invalid : ((Byte_obj_val)tid_obj).Val();
|
||||
int tid_end_pos = tid_trie.Match_pos();
|
||||
switch (tid_val) {
|
||||
case Imap_itm_.Tid_desc: Parse_desc(tid_end_pos, itm_end); break;
|
||||
case Imap_itm_.Tid_dflt: Parse_dflt(tid_end_pos, itm_end); break;
|
||||
case Imap_itm_.Tid_shape_rect: Parse_shape(tid_val, tid_end_pos, itm_bgn, itm_end, 4); break;
|
||||
case Imap_itm_.Tid_shape_poly: Parse_shape(tid_val, tid_end_pos, itm_bgn, itm_end, Reqd_poly); break;
|
||||
case Imap_itm_.Tid_shape_circle: Parse_shape(tid_val, tid_end_pos, itm_bgn, itm_end, 3); break;
|
||||
default:
|
||||
case Imap_itm_.Tid_invalid: Parse_invalid(itm_bgn, itm_end); break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {usr_dlg.Warn_many("", "", "imap.parse:skipping line; page=~{0} line=~{1} err=~{2}", page_url.Xto_full_str_safe(), Bry_.Mid_safe(src, itm_bgn, itm_end), Err_.Message_gplx(e));}
|
||||
++itm_idx;
|
||||
}
|
||||
rv.Init(xtn_mgr, imap_img_src, imap_img, imap_dflt, imap_desc, (Imap_itm_shape[])shapes.To_ary_and_clear(Imap_itm_shape.class), (Imap_err[])errs.To_ary_and_clear(Imap_err.class));
|
||||
}
|
||||
private void Parse_comment(int itm_bgn, int itm_end) {} // noop comments; EX: "# comment\n"
|
||||
private void Parse_invalid(int itm_bgn, int itm_end) {usr_dlg.Warn_many("", "", "imap has invalid line: page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_u8(src, itm_bgn, itm_end));}
|
||||
private boolean Parse_desc(int itm_bgn, int itm_end) {
|
||||
xtn_mgr.Desc_assert();
|
||||
Btrie_slim_mgr trie = xtn_mgr.Desc_trie();
|
||||
byte tid_desc = Imap_desc_tid.parse_(trie, src, Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end), Bry_finder.Trim_bwd_space_tab(src, itm_bgn, itm_end));
|
||||
switch (tid_desc) {
|
||||
case Imap_desc_tid.Tid_null: return Add_err(Bool_.N, itm_bgn, itm_end, "imagemap_invalid_coord");
|
||||
case Imap_desc_tid.Tid_none: return true;
|
||||
}
|
||||
if (imap_img == null || imap_img.Img_link().Lnki_type() == Xop_lnki_type.Id_thumb) return true; // thumbs don't get desc
|
||||
imap_desc = new Imap_itm_desc(tid_desc);
|
||||
return true;
|
||||
}
|
||||
private void Parse_dflt(int itm_bgn, int itm_end) {
|
||||
imap_dflt = new Imap_itm_dflt();
|
||||
Init_link_owner(imap_dflt, src, itm_bgn, itm_end);
|
||||
}
|
||||
private boolean Parse_shape(byte shape_tid, int tid_end_pos, int itm_bgn, int itm_end, int reqd_pts) {
|
||||
boolean shape_is_poly = shape_tid == Imap_itm_.Tid_shape_poly;
|
||||
int pos = Bry_finder.Trim_fwd_space_tab(src, tid_end_pos, itm_end); // gobble any leading spaces
|
||||
int grp_end = Bry_finder.Find_fwd(src, Byte_ascii.Brack_bgn, pos, itm_end); // find first "["; note that this is a lazy way of detecting start of lnki / lnke; MW has complicated regex, but hopefully this will be enough; DATE:2014-10-22
|
||||
if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "No valid link was found");}
|
||||
int num_bgn = -1, comma_pos = -1, pts_len = 0;
|
||||
while (true) {
|
||||
boolean last = pos == grp_end;
|
||||
byte b = last ? Byte_ascii.Space : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Comma: if (comma_pos == -1) comma_pos = pos; break;
|
||||
default: if (num_bgn == -1) num_bgn = pos; break;
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab:
|
||||
if (num_bgn != -1) {
|
||||
byte[] num_bry = comma_pos == -1 ? Bry_.Mid(src, num_bgn, pos) : Bry_.Mid(src, num_bgn, comma_pos); // if commas exist, treat first as decimal; echo(intval(round('1,2,3,4' * 1))) -> 1; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
double num = Bry_.Xto_double_or(num_bry, Double_.NaN);
|
||||
if (Double_.IsNaN(num)) {
|
||||
if (shape_is_poly) // poly code in ImageMap_body.php accepts invalid words and converts to 0; EX:"word1"; PAGE:uk.w:Стратосфера; DATE:2014-07-26
|
||||
num = 0;
|
||||
else
|
||||
return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_invalid_coord");
|
||||
}
|
||||
num_bgn = -1; comma_pos = -1;
|
||||
pts.Add(Double_obj_val.new_(num));
|
||||
++pts_len;
|
||||
if (pts_len == reqd_pts) // NOTE: MW allows more points, but doesn't show them; EX: rect 1 2 3 4 5 -> rect 1 2 3 4; PAGE:en.w:Kilauea DATE:2014-07-28; EX:1 2 3 4 <!-- --> de.w:Wilhelm_Angele DATE:2014-10-30
|
||||
last = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (last) break;
|
||||
++pos;
|
||||
}
|
||||
if (reqd_pts == Reqd_poly) {
|
||||
if (pts_len == 0) return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_missing_coord");
|
||||
else if (pts_len % 2 != 0) return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_poly_odd");
|
||||
}
|
||||
else {
|
||||
if (pts_len < reqd_pts) return Add_err(Bool_.Y, itm_bgn, itm_end, "imagemap_missing_coord");
|
||||
}
|
||||
pos = Bry_finder.Trim_fwd_space_tab(src, pos, itm_end);
|
||||
Imap_itm_shape shape_itm = new Imap_itm_shape(shape_tid, (Double_obj_val[])pts.To_ary_and_clear(Double_obj_val.class));
|
||||
Init_link_owner(shape_itm, src, pos, itm_end);
|
||||
shapes.Add(shape_itm);
|
||||
return true;
|
||||
}
|
||||
private boolean Add_err(boolean clear_pts, int bgn, int end, String err_key) {
|
||||
usr_dlg.Warn_many("", "", err_key + ": page=~{0} line=~{1}", page_url.Xto_full_str_safe(), String_.new_u8(src, bgn, end));
|
||||
errs.Add(new Imap_err(itm_idx, err_key));
|
||||
if (clear_pts) pts.Clear();
|
||||
return false;
|
||||
}
|
||||
private void Init_link_owner(Imap_link_owner link_owner, byte[] src, int bgn, int end) {
|
||||
byte[] link_tkn_src = Bry_.Mid(src, bgn, end);
|
||||
Xop_tkn_itm link_tkn = Parse_link(link_tkn_src);
|
||||
if (link_tkn == null) {Add_err(Bool_.N, bgn, end, "imap.invalid link_owner"); return;} // exit early if invalid; PAGE:de.u:PPA/Raster/TK25/51/18/12/20; DATE:2015-02-02
|
||||
link_tkn_src = imap_root.Data_mid(); // NOTE:must re-set link_tkn_src since link_tkn is expanded wikitext; i.e.: not "{{A}}" but "expanded"; PAGE:fr.w:Arrondissements_de_Lyon DATE:2014-08-12
|
||||
Imap_link_owner_.Init(link_owner, app, wiki, link_tkn_src, link_tkn);
|
||||
}
|
||||
private Xop_tkn_itm Parse_link(byte[] raw) {
|
||||
imap_root.Clear();
|
||||
imap_ctx.Clear();
|
||||
wiki.Parser().Parse_text_to_wdom(imap_root, imap_ctx, wiki.Appe().Tkn_mkr(), raw, 0);
|
||||
int subs_len = imap_root.Subs_len();
|
||||
for (int i = 0; i < subs_len; ++i) {
|
||||
Xop_tkn_itm sub = imap_root.Subs_get(i);
|
||||
switch (sub.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_lnki:
|
||||
case Xop_tkn_itm_.Tid_lnke:
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private int Parse_img(Imap_map imap, int itm_bgn, int itm_end, int src_end) {
|
||||
int img_bgn = Bry_finder.Trim_fwd_space_tab(src, itm_bgn, itm_end); // trim ws
|
||||
int img_end = Parse_img__get_img_end(itm_end, src_end);
|
||||
imap_img_src = Bry_.Add(Xop_tkn_.Lnki_bgn, Bry_.Mid(src, img_bgn, img_end), Xop_tkn_.Lnki_end);
|
||||
Xop_tkn_itm tkn_itm = Parse_link(imap_img_src); // NOTE: need to parse before imap_root.Data_mid() below
|
||||
imap_img_src = imap_root.Data_mid(); // need to re-set src to pick up templates; EX: <imagemap>File:A.png|thumb|{{Test_template}}\n</imagemap>; PAGE:en.w:Kilauea; DATE:2014-07-27
|
||||
Xopg_redlink_logger file_wkr = wiki_ctx.Lnki().File_wkr(); // NOTE: do not do imap_ctx.Lnki(); imap_ctx is brand new
|
||||
if ( tkn_itm == null // no lnki or lnke
|
||||
|| tkn_itm.Tkn_tid() != Xop_tkn_itm_.Tid_lnki // no lnki; occurs with badly constructed maps; PAGE:en.w:Demography_of_the_United_Kingdom DATE:2015-01-22
|
||||
)
|
||||
imap_ctx.Wiki().Appe().Usr_dlg().Warn_many("", "", "image_map failed to find lnki; page=~{0} imageMap=~{1}", String_.new_u8(imap_ctx.Cur_page().Ttl().Full_txt()), String_.new_u8(imap_img_src));
|
||||
else {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn_itm;
|
||||
imap_img = new Imap_itm_img(lnki_tkn);
|
||||
lnki_tkn.Lnki_file_wkr_(imap);
|
||||
wiki_ctx.Cur_page().Lnki_list().Add(lnki_tkn);
|
||||
if (file_wkr != null) file_wkr.Wkr_exec(wiki_ctx, src, lnki_tkn, gplx.xowa.bldrs.cmds.files.Xob_lnki_src_tid.Tid_imageMap);
|
||||
}
|
||||
return img_end;
|
||||
}
|
||||
private int Parse_img__get_img_end(int line_end, int src_end) { // heuristic to handle images that span more than one line via ref; en.w:Archaea DATE:2014-08-22
|
||||
int rv = line_end;
|
||||
int pos = line_end + 1;
|
||||
while (pos < src_end) {
|
||||
pos = Bry_finder.Trim_fwd_space_tab(src, pos, src_end); // trim ws
|
||||
if (pos == src_end) break;
|
||||
byte b = src[pos];
|
||||
if (b == Byte_ascii.Nl) // new-line; end
|
||||
break;
|
||||
else {
|
||||
Object tid_obj = tid_trie.Match_bgn_w_byte(b, src, pos, src_end);
|
||||
if (tid_obj == null) { // not a known imap line; assume continuation of img line and skip to next line
|
||||
imap_ctx.Wiki().Appe().Usr_dlg().Note_many("", "", "image_map extending image over multiple lines; page=~{0} imageMap=~{1}", String_.new_u8(imap_ctx.Cur_page().Ttl().Full_txt()), String_.new_u8(imap_img_src));
|
||||
int next_line = Bry_finder.Find_fwd(src, Byte_ascii.Nl, pos);
|
||||
if (next_line == Bry_finder.Not_found) next_line = src_end;
|
||||
rv = next_line;
|
||||
pos = rv + 1;
|
||||
}
|
||||
else // known imap line; stop
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Btrie_slim_mgr tid_trie = Btrie_slim_mgr.ci_ascii_() // names are not i18n'd; // NOTE:ci.ascii:MW_const.en
|
||||
.Add_str_byte("desc" , Imap_itm_.Tid_desc)
|
||||
.Add_str_byte("#" , Imap_itm_.Tid_comment)
|
||||
.Add_bry_bval(Imap_itm_.Key_dflt , Imap_itm_.Tid_dflt)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_rect , Imap_itm_.Tid_shape_rect)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_circle , Imap_itm_.Tid_shape_circle)
|
||||
.Add_bry_bval(Imap_itm_.Key_shape_poly , Imap_itm_.Tid_shape_poly)
|
||||
;
|
||||
private static final int Reqd_poly = -1;
|
||||
}
|
||||
101
400_xowa/src/gplx/xowa/xtns/imaps/Imap_parser_tst.java
Normal file
101
400_xowa/src/gplx/xowa/xtns/imaps/Imap_parser_tst.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*; import gplx.core.primitives.*;
|
||||
public class Imap_parser_tst {
|
||||
@Before public void init() {fxt.Reset();} private Imap_parser_fxt fxt = new Imap_parser_fxt();
|
||||
@Test public void Rect_pass() {fxt.Test_shape("rect 1 2 3 4 [[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));}
|
||||
@Test public void Rect_pass_many() {fxt.Test_shape("rect 1 2 3 4 5 6[[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));} // PURPOSE: MW allows extra points to be passed; PAGE:en.w:Kilauea DATE:2014-07-28
|
||||
@Test public void Rect_pass_invalid() {fxt.Test_shape("rect 1 2 3 4 a b [[A]]" , fxt.itm_rect_("[[A]]", 1, 2, 3, 4));} // PURPOSE: MW only scans first 4 tokens for numbers; PAGE:de.w:Wilhelm_Angele DATE:2014-10-30
|
||||
@Test public void Circle_pass() {fxt.Test_shape("circle 1 2 3 [[A]]" , fxt.itm_circle_("[[A]]", 1, 2, 3));}
|
||||
@Test public void Poly_pass() {fxt.Test_shape("poly 1 2 3 4 5 6 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4, 5, 6));}
|
||||
@Test public void Poly_pass_chars() {fxt.Test_shape("poly a b [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:uk.w:Стратосфера; DATE:2014-07-26
|
||||
@Test public void Poly_pass_chars_2() {fxt.Test_shape("poly 1a 2a [[A]]" , fxt.itm_poly_("[[A]]", 0, 0));} // PURPOSE: non-numeric should be converted to 0; PAGE:ru.w:Системный_блок; DATE:2014-10-22
|
||||
@Test public void Poly_pass_dots() {fxt.Test_shape("poly 1.2 3.4 [[A]]" , fxt.itm_poly_("[[A]]", 1.2d, 3.4d));} // PURPOSE: make sure decimals are handled correctly
|
||||
@Test public void Poly_pass_commas() {fxt.Test_shape("poly 1, 2, 3, 4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 2, 3, 4));} // PURPOSE: commas should be ignored; PAGE:de.w:Kaimnitz; DATE:2014-08-05
|
||||
@Test public void Poly_pass_commas_2() {fxt.Test_shape("poly 1,2 3,4 [[A]]" , fxt.itm_poly_("[[A]]", 1, 3));} // PURPOSE: commas should be ignored for purpose of parse; PAGE:fr.w:Gouesnou; DATE:2014-08-12
|
||||
@Test public void Rect_fail() {fxt.Test_shape_err("rect 1 2 3 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Circle_fail() {fxt.Test_shape_err("circle 1 2 [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Poly_fail_odd() {fxt.Test_shape_err("poly 1 2 3 [[A]]" , "imagemap_poly_odd");}
|
||||
@Test public void Poly_fail_zero() {fxt.Test_shape_err("poly [[A]]" , "imagemap_missing_coord");}
|
||||
@Test public void Circle_fail_invalid() {fxt.Test_shape_err("rect 1 2..3 4 [[A]]" , "imagemap_invalid_coord");}
|
||||
}
|
||||
class Imap_fxt_base {
|
||||
protected Xoae_app app; protected Xowe_wiki wiki;
|
||||
@gplx.Virtual public void Reset() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
wiki.Ctx().Para().Enabled_n_();
|
||||
}
|
||||
public Imap_itm_shape itm_rect_(String link, double... pts_ary) {return itm_shape_(Imap_itm_.Tid_shape_rect, link, pts_ary);}
|
||||
public Imap_itm_shape itm_circle_(String link, double... pts_ary) {return itm_shape_(Imap_itm_.Tid_shape_circle, link, pts_ary);}
|
||||
public Imap_itm_shape itm_poly_(String link, double... pts_ary) {return itm_shape_(Imap_itm_.Tid_shape_poly, link, pts_ary);}
|
||||
private Imap_itm_shape itm_shape_(byte tid, String link, double... pts_ary) {
|
||||
int pts_len = pts_ary.length;
|
||||
Double_obj_val[] pts_doubles = new Double_obj_val[pts_len];
|
||||
for (int i = 0; i < pts_len; ++i)
|
||||
pts_doubles[i] = Double_obj_val.new_(pts_ary[i]);
|
||||
byte[] link_bry = Bry_.new_u8(link);
|
||||
Imap_itm_shape rv = new Imap_itm_shape(tid, pts_doubles);
|
||||
Imap_link_owner_.Init(rv, app, wiki, link_bry, Make_link_tkn(link_bry));
|
||||
return rv;
|
||||
}
|
||||
private Xop_tkn_itm Make_link_tkn(byte[] src) {
|
||||
Xop_root_tkn root_tkn = new Xop_root_tkn();
|
||||
wiki.Parser().Parse_text_to_wdom(root_tkn, wiki.Ctx(), app.Tkn_mkr(), src, Xop_parser_.Doc_bgn_bos);
|
||||
return root_tkn.Subs_get(0);
|
||||
}
|
||||
}
|
||||
class Imap_parser_fxt extends Imap_fxt_base {
|
||||
private Imap_parser parser;
|
||||
private Imap_map imap;
|
||||
@Override public void Reset() {
|
||||
super.Reset();
|
||||
Xoa_url url = Xoa_url.new_(wiki.Domain_bry(), Bry_.new_a7("Test_1"));
|
||||
Imap_xtn_mgr xtn_mgr = new Imap_xtn_mgr();
|
||||
parser = new Imap_parser(xtn_mgr);
|
||||
parser.Init(wiki, url, Gfo_usr_dlg_.Noop);
|
||||
parser.Clear();
|
||||
imap = new Imap_map(1);
|
||||
}
|
||||
public void Test_shape(String raw_str, Imap_itm_shape expd) {
|
||||
raw_str = "File:A.png\n" + raw_str;
|
||||
byte[] raw = Bry_.new_u8(raw_str);
|
||||
parser.Parse(imap, raw, 0, raw.length);
|
||||
Imap_itm_shape[] actl_ary = imap.Shapes();
|
||||
Imap_itm_shape actl = actl_ary == null | actl_ary.length != 1 ? null : (Imap_itm_shape)actl_ary[0];
|
||||
if (actl == null && expd == null) {} // noop; test passed
|
||||
else if (actl == null && expd != null) {Tfds.Fail("actl should not be null", raw);}
|
||||
else if (actl != null && expd == null) {Tfds.Fail("actl should be null", raw);}
|
||||
else {
|
||||
Tfds.Eq(expd.Itm_tid(), actl.Itm_tid(), "tid");
|
||||
Tfds.Eq_ary(expd.Shape_pts(), actl.Shape_pts(), "pts");
|
||||
Tfds.Eq(String_.new_u8(expd.Link_href()), String_.new_u8(actl.Link_href()));
|
||||
Tfds.Eq(String_.new_u8(expd.Link_text()), String_.new_u8(actl.Link_text()));
|
||||
}
|
||||
Tfds.Eq(0, imap.Errs().length, "expd 0 errors");
|
||||
}
|
||||
public void Test_shape_err(String raw_str, String expd_err) {
|
||||
raw_str = "File:A.png\n" + raw_str;
|
||||
byte[] raw = Bry_.new_u8(raw_str);
|
||||
parser.Parse(imap, raw, 0, raw.length);
|
||||
Imap_err[] err_ary = imap.Errs();
|
||||
Tfds.Eq(1, err_ary.length, "expd 1 err");
|
||||
Tfds.Eq(expd_err, err_ary[0].Err_key());
|
||||
}
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/xtns/imaps/Imap_pts_fmtr_arg.java
Normal file
34
400_xowa/src/gplx/xowa/xtns/imaps/Imap_pts_fmtr_arg.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
class Imap_pts_fmtr_arg implements Bry_fmtr_arg {
|
||||
private double scale = 1; private Double_obj_val[] pts;
|
||||
public void Scale_(double v) {this.scale = v;}
|
||||
public void Pts_(Double_obj_val[] v) {this.pts = v;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
int pts_len = pts.length;
|
||||
for (int i = 0; i < pts_len; ++i) {
|
||||
Double_obj_val pt = pts[i];
|
||||
if (i != 0) bfr.Add_byte_comma();
|
||||
int pt_int = (int)pt.Val();
|
||||
pt_int = (int)Math_.Round(scale * pt_int, 0);
|
||||
bfr.Add_int_variable(pt_int);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/xtns/imaps/Imap_xnde.java
Normal file
38
400_xowa/src/gplx/xowa/xtns/imaps/Imap_xnde.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.parsers.logs.*;
|
||||
public class Imap_xnde implements Xox_xnde {
|
||||
private Imap_xtn_mgr xtn_mgr;
|
||||
private Imap_map imap_data;
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
xtn_mgr = wiki.Xtn_mgr().Xtn_imap();
|
||||
xtn_mgr.Xtn_assert();
|
||||
Xoae_page page = ctx.Cur_page();
|
||||
page.Html_data().Module_mgr().Itm__popups().Bind_hover_area_(true);
|
||||
page.Html_data().Xtn_imap_exists_y_();
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
imap_data = xtn_mgr.Parser().Parse(wiki, ctx, root, src, xnde);
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_imageMap, src, xnde);
|
||||
} 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, Xop_xnde_tkn xnde, byte[] src) {
|
||||
if (imap_data.Invalid()) return;
|
||||
html_wtr.Write_tkn(bfr, ctx, hctx, imap_data.Img_src(), xnde, Xoh_html_wtr.Sub_idx_null, imap_data.Img().Img_link());
|
||||
}
|
||||
}
|
||||
228
400_xowa/src/gplx/xowa/xtns/imaps/Imap_xnde_html_all_tst.java
Normal file
228
400_xowa/src/gplx/xowa/xtns/imaps/Imap_xnde_html_all_tst.java
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Imap_xnde_html_all_tst {
|
||||
@Before public void init() {fxt.Reset();} private Imap_xnde_html_fxt fxt = new Imap_xnde_html_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap>"
|
||||
, "File:A.png|thumb|123px|a1"
|
||||
, "circle 0 0 5 [[B|b1]]"
|
||||
, "rect 0 0 4 8 [[C|c1]]"
|
||||
, "desc none"
|
||||
, "</imagemap>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
|
||||
, " <div id='imap_div_0' class=\"noresize\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " <area href=\"/wiki/B\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
|
||||
, " <area href=\"/wiki/C\" shape=\"rect\" coords=\"0,0,4,8\" alt=\"c1\" title=\"c1\"/>"
|
||||
, " </map>"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Caption_xml() { // PURPOSE: xnde in caption was being escaped; PAGE:en.w:Council_of_Europe; DATE:2014-07-25
|
||||
fxt.Test_html_full_frag("<imagemap>File:A.png|thumb|<b>c</b>\n</imagemap>", "<b>c</b>");
|
||||
}
|
||||
@Test public void Default() {
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap>"
|
||||
, "File:A.png|thumb|123px|a1"
|
||||
, "default [[B|b1]]"
|
||||
, "</imagemap>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
|
||||
, " <div id='imap_div_0' class=\"noresize\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " </map>"
|
||||
, " <a href=\"/wiki/B\" title=\"b1\">"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Desc() {
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap>"
|
||||
, "File:A.png|123px|a1"
|
||||
, "desc top-left"
|
||||
, "</imagemap>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id='imap_div_0' class=\"noresize\" style=\"height:0px; width: 123px;\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " </map>"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"a1\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
|
||||
, " <div style=\"margin-left:0px; margin-top:1px; text-align:left;\">"
|
||||
, " <a href=\"/wiki/File:A.png\" title=\"click here\">"
|
||||
, " <img alt=\"click here\" src=\"file:///mem/xowa/bin/any/xowa/xtns/ImageMap/imgs/desc-20.png\" style=\"border: none;\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Lnke() { // PURPOSE: handle shapes with lnke; PAGE:en.w:Cholesterolt DATE:2014-07-25
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap>"
|
||||
, "File:A.png|thumb|123px|a1"
|
||||
, "circle 0 0 5 [[http://b.org b1]]"
|
||||
, "desc none"
|
||||
, "</imagemap>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
|
||||
, " <div id='imap_div_0' class=\"noresize\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " <area href=\"http://b.org\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
|
||||
, " </map>"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Err_trailing_ws() { // PURPOSE: empty 1st line causes failure
|
||||
fxt.Test_html_full_frag(String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap> "
|
||||
, "File:A.png|thumb|test_caption"
|
||||
, "</imagemap>"
|
||||
), "test_caption" // no error if test_caption appears;
|
||||
);
|
||||
}
|
||||
@Test public void Para_omitted() { // PURPOSE: imagemap should not be automatically enclosed in para; PAGE:cs.w:Seznam_clenu_ctrn<72>ct<63>ho_Knesetu; DATE:2014-05-08;
|
||||
fxt.Fxt().Init_para_y_();
|
||||
fxt.Test_html_full_str("<imagemap>File:A.png</imagemap> a", fxt.Frag_html_full() + " a"); // NOTE: "a" no longer enclosed in <p>; DATE:2014-07-25
|
||||
fxt.Fxt().Init_para_n_();
|
||||
}
|
||||
@Test public void Xnde_double_pipe() {// PURPOSE: if || is inside table and imagemap, treat as lnki; EX:w:United_States_presidential_election,_1992; DATE:2014-03-29; DATE:2014-05-06
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "| z"
|
||||
, "<imagemap>"
|
||||
, "File:A.png||123px|b" // NOTE: "||" should not be tblw; also should not be pipe + text; if it is pipe + text, then caption will be "|123px" and width will be -1; DATE:2014-05-06
|
||||
, "</imagemap>"
|
||||
, "|}"
|
||||
) , String_.Concat_lines_nl_skip_last
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td> z"
|
||||
, "<div id='imap_div_0' class=\"noresize\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " </map>"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"b\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>" // NOTE: width must be 123, not 0
|
||||
, " </div>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Template_image() { // PURPOSE: handle templates in caption; PAGE:en.w:Kilauea; DATE:2014-07-27
|
||||
fxt.Fxt().Init_page_create("Template:Test_template", "xyz");
|
||||
fxt.Test_html_full_frag("<imagemap>File:A.png|thumb|{{Test_template}}\n</imagemap>", "xyz");
|
||||
}
|
||||
@Test public void Template_shape() { // PURPOSE: handle templates in shape; PAGE:fr.w:Arrondissements_de_Lyon DATE:2014-08-12
|
||||
fxt.Fxt().Init_page_create("Template:B1", "<b>b1</b>"); // note that an xnde is a better example as it will throw ArrayOutOfBounds error
|
||||
fxt.Test_html_full_str(String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap>"
|
||||
, "File:A.png|thumb|123px|a1"
|
||||
, "circle 0 0 5 [[B|{{b1}}]]"
|
||||
, "desc none"
|
||||
, "</imagemap>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
|
||||
, " <div id='imap_div_0' class=\"noresize\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " <area href=\"/wiki/B\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
|
||||
, " </map>"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " a1"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Template_multi_line() { // PURPOSE: handle multiple-line captions; PAGE:en.w:Archaea; DATE:2014-08-22
|
||||
fxt.Test_html_full_frag(String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap>"
|
||||
, "File:A.png|thumb|<ref>text"
|
||||
, "</ref>"
|
||||
, "</imagemap>"
|
||||
), "id=\"cite_ref-0\"");
|
||||
}
|
||||
}
|
||||
class Imap_xnde_html_fxt {
|
||||
public void Reset() {
|
||||
fxt.Reset();
|
||||
Xol_msg_itm msg = fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_a7("imagemap_description"));
|
||||
msg.Atrs_set(Bry_.new_a7("click here"), false, false);
|
||||
}
|
||||
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt = new Xop_fxt();
|
||||
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);}
|
||||
public String Frag_html_full() {
|
||||
return String_.Concat_lines_nl_skip_last
|
||||
( "<div id='imap_div_0' class=\"noresize\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " </map>"
|
||||
, " <img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" usemap=\"#imageMap_1_1\"/>"
|
||||
, " </div>"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Imap_xnde_html_itm_tst {
|
||||
@Before public void init() {fxt.Reset();} private Imap_html_bldr_fxt fxt = new Imap_html_bldr_fxt();
|
||||
@Test public void Rect() {fxt.Test_shape_html(fxt.itm_rect_("[[A|b]]", 1, 2, 3, 4), "\n <area href=\"/wiki/A\" shape=\"rect\" coords=\"1,2,3,4\" alt=\"b\" title=\"b\"/>");}
|
||||
@Test public void Circle() {fxt.Test_shape_html(fxt.itm_circle_("[[A|b]]", 1, 2, 3 ), "\n <area href=\"/wiki/A\" shape=\"circle\" coords=\"1,2,3\" alt=\"b\" title=\"b\"/>");}
|
||||
@Test public void Poly() {fxt.Test_shape_html(fxt.itm_poly_("[[A|b]]", 1, 2, 3, 4), "\n <area href=\"/wiki/A\" shape=\"poly\" coords=\"1,2,3,4\" alt=\"b\" title=\"b\"/>");}
|
||||
}
|
||||
class Imap_html_bldr_fxt extends Imap_fxt_base {
|
||||
private Bry_bfr bfr = Bry_bfr.new_();
|
||||
private Imap_pts_fmtr_arg pts_fmtr_arg = new Imap_pts_fmtr_arg();
|
||||
public void Test_shape_html(Imap_itm_shape shape, String expd) {
|
||||
Imap_shapes_fmtr.Fmt_shape(bfr, Imap_html_fmtrs.Area, pts_fmtr_arg, shape);
|
||||
Tfds.Eq(expd, bfr.Xto_str_and_clear());
|
||||
}
|
||||
}
|
||||
48
400_xowa/src/gplx/xowa/xtns/imaps/Imap_xtn_mgr.java
Normal file
48
400_xowa/src/gplx/xowa/xtns/imaps/Imap_xtn_mgr.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.wikis.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
|
||||
public class Imap_xtn_mgr extends Xox_mgr_base implements GfoInvkAble {
|
||||
private boolean init;
|
||||
@Override public boolean Enabled_default() {return true;}
|
||||
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("imageMap");
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
@gplx.Internal protected Imap_parser Parser() {return parser;} private Imap_parser parser;
|
||||
public void Desc_assert() {
|
||||
if (desc_trie != null) return;
|
||||
desc_trie = Imap_desc_tid.trie_(wiki);
|
||||
desc_msg = wiki.Msg_mgr().Val_by_key_obj("imagemap_description");
|
||||
desc_icon_url = wiki.Appe().Fsys_mgr().Bin_xtns_dir().GenSubFil_nest("ImageMap", "imgs", "desc-20.png").To_http_file_bry();
|
||||
}
|
||||
public Btrie_slim_mgr Desc_trie() {return desc_trie;} private Btrie_slim_mgr desc_trie;
|
||||
public byte[] Desc_msg() {return desc_msg;} private byte[] desc_msg;
|
||||
public byte[] Desc_icon_url() {return desc_icon_url;} private byte[] desc_icon_url;
|
||||
public Xoh_arg_img_core Img_core_fmtr(boolean hctx_is_hdump) {return hctx_is_hdump ? img_core_hdump : img_core_basic;}
|
||||
private final Xoh_arg_img_core img_core_basic = new Xoh_arg_img_core__basic(), img_core_hdump = new Xoh_arg_img_core__hdump();
|
||||
@Override public Xox_mgr Clone_new() {return new Imap_xtn_mgr();}
|
||||
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
}
|
||||
public void Xtn_assert() {
|
||||
if (init) return;
|
||||
parser = new Imap_parser(this);
|
||||
init = true;
|
||||
}
|
||||
public void Clear() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user