diff options
author | Norbert Preining <norbert@preining.info> | 2020-07-08 03:01:45 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-07-08 03:01:45 +0000 |
commit | 8c3fedd243b69349b426144e5e2b94ef4aea6a4c (patch) | |
tree | f5842753f11a90141f3cc2e356c3a04766e8d81e /graphics/asymptote/jsfile.cc | |
parent | ef87f13c4503a2aa4a9098cbf33e0bfcad19008e (diff) |
CTAN sync 202007080301
Diffstat (limited to 'graphics/asymptote/jsfile.cc')
-rw-r--r-- | graphics/asymptote/jsfile.cc | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/graphics/asymptote/jsfile.cc b/graphics/asymptote/jsfile.cc index 93451b0f0d..4849940ba9 100644 --- a/graphics/asymptote/jsfile.cc +++ b/graphics/asymptote/jsfile.cc @@ -10,17 +10,23 @@ using namespace settings; namespace camp { -void jsfile::copy(string name) { +void jsfile::copy(string name, bool header) +{ std::ifstream fin(locateFile(name).c_str()); string s; + if(header) getline(fin,s); while(getline(fin,s)) out << s << newl; } -void jsfile::open(string name) { +void jsfile::header(string name) +{ out.open(name); out << "<!DOCTYPE html>" << newl << newl; - +} + +void jsfile::comment(string name) +{ out << "<!-- Use the following line to embed this file within another web page:" << newl << newl << "<iframe src=\"" << name @@ -29,16 +35,52 @@ void jsfile::open(string name) { << "\" frameborder=\"0\"></iframe>" << newl << newl << "-->" << newl << newl; +} - out.precision(getSetting<Int>("digits")); +void jsfile::meta(string name, bool svg) +{ out << "<html lang=\"\">" << newl << newl << "<head>" << newl << "<title>" << stripExt(name) << "</title>" << newl << newl - << "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>" << newl - << "<meta name=\"viewport\" content=\"user-scalable=no\"/>" << newl + << "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>" << newl; + if(svg) { + out << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>" + << newl << "</head>"; + } else { + out << "<meta name=\"viewport\" content=\"user-scalable=no\"/>"; + } + out << newl << newl; +} + +void jsfile::footer(string name) +{ + out << newl << "</body>" + << newl << newl << "</html>" << newl; + out.flush(); + if(verbose > 0) + cout << "Wrote " << name << endl; +} + +void jsfile::svgtohtml(string prefix) +{ + string name=buildname(prefix,"html"); + header(name); + meta(name); + out << "<body>" << newl << newl; + copy(locateFile(auxname(prefix,"svg")),true); + footer(name); +} + +void jsfile::open(string name) +{ + header(name); + comment(name); + meta(name,false); + + out.precision(getSetting<Int>("digits")); if(getSetting<bool>("offline")) { out << "<script>" << newl; @@ -99,7 +141,8 @@ void jsfile::open(string name) { out << "];" << newl << newl; } -jsfile::~jsfile() { +void jsfile::finish(string name) +{ size_t ncenters=drawElement::center.size(); if(ncenters > 0) { out << "Centers=["; @@ -108,15 +151,13 @@ jsfile::~jsfile() { out << newl << "];" << newl; } out << "</script>" - << newl << newl << "</head>" + << newl << "</head>" << newl << newl << "<body style=\"overflow: hidden;\" onload=\"webGLStart();\">" << newl << "<canvas id=\"Asymptote\" width=\"" << gl::fullWidth << "\" height=\"" << gl::fullHeight << "\" style=\"border: none;\">" - << newl << "</canvas>" - << newl << "</body>" - << newl << newl << "</html>" - << newl; + << newl << "</canvas>"; + footer(name); } void jsfile::addColor(const prc::RGBAColour& c) |