1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

v2.10.3.1

This commit is contained in:
gnosygnu
2015-10-18 22:17:57 -04:00
parent 8e18af05b6
commit 4f43f51b18
1935 changed files with 12500 additions and 12889 deletions

View File

@@ -16,11 +16,11 @@ 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.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*;
public class Math_nde implements Xox_xnde, Xop_xnde_atr_parser {
import gplx.xowa.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Math_nde implements Xox_xnde {
public Xop_xnde_tkn Xnde() {throw Err_.new_unimplemented();}
public void Xatr_parse(Xowe_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_obj) {}
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) {
Xof_math_mgr math_mgr = wiki.Appe().File_mgr().Math_mgr();
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_math, src, xnde);

View File

@@ -16,8 +16,8 @@ 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.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
import gplx.xowa.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.vnts.*;
public class Xof_math_html_wtr {
private Xof_math_itm tmp_math_itm = new Xof_math_itm();
private Bry_fmtr math_fmtr_latex = Bry_fmtr.new_("<img id='xowa_math_img_~{math_idx}' src='' width='' height=''/><span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>", "math_idx", "math_text");
@@ -36,15 +36,20 @@ public class Xof_math_html_wtr {
bfr.Add_str(tmp_math_itm.Png_url().To_http_file_str());
bfr.Add(Xoh_consts.__inline_quote);
}
else {
int id = page.File_math().Count();
Xof_math_itm new_math_itm = tmp_math_itm.Clone().Id_(id);
Bry_fmtr math_fmtr = renderer_is_latex ? math_fmtr_latex : math_fmtr_mathjax;
math_fmtr.Bld_bfr_many(tmp_bfr, id, math_bry);
bfr.Add_bfr_and_clear(tmp_bfr);
if (enabled && renderer_is_latex) // NOTE: only generate images if math is enabled; otherwise "downloading" prints at bottom of screen, but no action (also a lot of file IO)
page.File_math().Add(new_math_itm);
}
else
Write_for_mathjax(bfr, page, enabled, renderer_is_latex, math_bry, tmp_bfr);
}
private void Write_for_mathjax(Bry_bfr bfr, Xoae_page page, boolean enabled, boolean renderer_is_latex, byte[] math_bry, Bry_bfr tmp_bfr) {
int id = page.File_math().Count();
Xof_math_itm new_math_itm = tmp_math_itm.Clone().Id_(id);
Bry_fmtr math_fmtr = renderer_is_latex ? math_fmtr_latex : math_fmtr_mathjax;
boolean armor_math = page.Lang().Vnt_mgr().Enabled() && !renderer_is_latex; // REF.MW:LangConverter.php|armourMath
if (armor_math) bfr.Add(Vnt_convert_lang.Bry__armor_bgn);
math_fmtr.Bld_bfr_many(tmp_bfr, id, math_bry);
bfr.Add_bfr_and_clear(tmp_bfr);
if (armor_math) bfr.Add(Vnt_convert_lang.Bry__armor_end);
if (enabled && renderer_is_latex) // NOTE: only generate images if math is enabled; otherwise "downloading" prints at bottom of screen, but no action (also a lot of file IO)
page.File_math().Add(new_math_itm);
}
private static byte[] Escape_tex(Bry_bfr tmp_bfr, boolean mathjax, byte[] bry) {return Escape_tex(false, tmp_bfr, mathjax, bry, 0, bry.length);}
private static byte[] Escape_tex(boolean write_to_bfr, Bry_bfr bfr, boolean mathjax, byte[] bry, int bgn, int end) {
@@ -80,6 +85,6 @@ public class Xof_math_html_wtr {
if (write_to_bfr)
return null;
else
return dirty ? bfr.Xto_bry_and_clear() : bry;
return dirty ? bfr.To_bry_and_clear() : bry;
}
}

View File

@@ -38,7 +38,7 @@ public class Xof_math_mgr implements GfoInvkAble {
}
public boolean Find_itm(Xof_math_itm rv, String wiki_key, byte[] math_bry) {
Make_itm(rv, wiki_key, math_bry);
return Io_mgr.I.ExistsFil(rv.Png_url());
return Io_mgr.Instance.ExistsFil(rv.Png_url());
}
public boolean Renderer_is_mathjax() {return renderer_is_mathjax;} public void Renderer_is_mathjax_(boolean v) {renderer_is_mathjax = v;} private boolean renderer_is_mathjax = true;
private Io_url Make_png_fil(Io_url math_dir, String hash) {
@@ -49,7 +49,7 @@ public class Xof_math_mgr implements GfoInvkAble {
.Add(String_.CharAt(hash, 2)).Add(Math_dir_spr)
.Add(hash).Add(".png")
;
return Io_url_.new_fil_(tmp_sb.Xto_str_and_clear());
return Io_url_.new_fil_(tmp_sb.To_str_and_clear());
}
public boolean MakePng(byte[] math, String hash, Io_url png_url, String prog_fmt) {
if (!enabled) return false;
@@ -57,14 +57,14 @@ public class Xof_math_mgr implements GfoInvkAble {
Io_url tex_url = tmp_dir.GenSubFil("xowa_math_temp.tex");
String latex = Latex_wrap(math);
prog_fmt = String_.Replace(prog_fmt, "~", "~~"); // double-up ~ or else will break in progress bar
Io_mgr.I.SaveFilStr(tex_url, latex);
Io_mgr.Instance.SaveFilStr(tex_url, latex);
cmd_convert_tex_to_dvi.Prog_fmt_(prog_fmt + " tex_to_dvi: ~{process_seconds} second(s); ~{process_exe_name} ~{process_exe_args}");
boolean pass = cmd_convert_tex_to_dvi.Run(tex_url.Raw(), tmp_dir.Xto_api()).Exit_code_pass();
if (!pass) {
app.Usr_dlg().Warn_many(GRP_KEY, "tex_to_dvi.fail", "fail: tex_to_dvi: error=~{0} latex=~{1}", cmd_convert_tex_to_dvi.Rslt_out(), latex);
}
// NOTE: latex sometimes throws errors, but will generate .dvi; for sake of simplicity; always try to run dvipng
Io_mgr.I.CreateDirIfAbsent(png_url.OwnerDir());
Io_mgr.Instance.CreateDirIfAbsent(png_url.OwnerDir());
cmd_convert_dvi_to_png.Prog_fmt_(prog_fmt + " dvi_to_png: ~{process_seconds} second(s); ~{process_exe_name} ~{process_exe_args}");
pass = cmd_convert_dvi_to_png.Run(tex_url.GenNewExt(".dvi"), png_url, tmp_dir.Xto_api()).Exit_code_pass();
if (!pass) {
@@ -93,7 +93,7 @@ public class Xof_math_mgr implements GfoInvkAble {
));
public boolean Enabled() {return enabled;} public Xof_math_mgr Enabled_(boolean v) {enabled = v; return this;} private boolean enabled = true;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
if (ctx.Match(k, Invk_enabled)) return Yn.To_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_renderer)) return renderer_is_mathjax ? "mathjax" : "latex";
else if (ctx.Match(k, Invk_renderer_)) renderer_is_mathjax = String_.Eq(m.ReadStr("v"), "mathjax");

View File

@@ -33,4 +33,9 @@ public class Xof_math_mgr_html_tst {
@Test public void Quote() { // PURPOSE: assert that quote is not escaped; DATE:2014-07-20
fxt.Test_html_full_str("<math>a\"b</math>", "<span id='xowa_math_txt_0'>a\"b</span>");
}
@Test public void Vnt() { // PURPOSE: if vnt, armor math; PAGE:sr.w:Земља; DATE:2015-10-11
fxt.Wiki().Lang().Vnt_mgr().Enabled_(Bool_.Y);
fxt.Test_html_full_str("<math>abc</math>", "-{R|<span id='xowa_math_txt_0'>abc</span>}-"); // NOTE: this also armors the id which is good for the mathjax.js
fxt.Wiki().Lang().Vnt_mgr().Enabled_(Bool_.N);
}
}

View File

@@ -56,7 +56,7 @@ public class Xof_math_subst_regy {
}
for (int i = 0; i < dollarSignCount; i++)
bfr.Add_byte(Byte_ascii.Dollar);
return bfr.Xto_bry_and_clear_and_trim();
return bfr.To_bry_and_clear_and_trim();
} boolean init = false;
public Xof_math_subst_regy Init() {
if (init) return this;

View File

@@ -77,7 +77,7 @@ public class Texvc_root implements Texvc_tkn {
if (regy_tkn.Update_end(uid, end))
regy_nde.Update_end(uid, end);
}
public String Print_tex_str(Bry_bfr bfr) {Print_tex_bry(bfr, src, 0); return bfr.Xto_str_and_clear();}
public String Print_tex_str(Bry_bfr bfr) {Print_tex_bry(bfr, src, 0); return bfr.To_str_and_clear();}
public void Print_tex_bry(Bry_bfr bfr, byte[] src, int indent) {
int subs_len = Subs__len();
for (int i = 0; i < subs_len; ++i) {
@@ -85,7 +85,7 @@ public class Texvc_root implements Texvc_tkn {
sub_tkn.Print_tex_bry(bfr, src, indent + 1);
}
}
public String Print_dbg_str(Bry_bfr bfr) {Print_dbg_bry(bfr, 0); return bfr.Xto_str_and_clear();}
public String Print_dbg_str(Bry_bfr bfr) {Print_dbg_bry(bfr, 0); return bfr.To_str_and_clear();}
public void Print_dbg_bry(Bry_bfr bfr, int indent) {
int len = this.Subs__len();
for (int i = 0; i < len; ++i) {

View File

@@ -49,7 +49,7 @@ public class Texvc_tkn_ {
int len = ary.length;
for (int i = 0; i < len; ++i)
ary[i].Print_dbg_bry(bfr, 0);
return bfr.Xto_str_and_clear();
return bfr.To_str_and_clear();
}
public static void Print_dbg_str__bgn(Bry_bfr bfr, int indent, Texvc_tkn tkn) {
if (indent > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2);