1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

use auto when possible

fix typo
This commit is contained in:
Lu Wang 2014-11-16 22:04:02 +08:00
parent 527e7b6216
commit 92413fdec3
15 changed files with 117 additions and 130 deletions

View File

@ -4,7 +4,7 @@ before_install:
- sudo add-apt-repository ppa:fontforge/fontforge --yes - sudo add-apt-repository ppa:fontforge/fontforge --yes
- sudo add-apt-repository ppa:coolwanglu/pdf2htmlex --yes - sudo add-apt-repository ppa:coolwanglu/pdf2htmlex --yes
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -qq libpoppler-dev libspiro-dev libcairo-dev libfreetype6-dev libltdl-dev libfontforge-dev libpango1.0-dev - sudo apt-get install -qq libpoppler-dev libspiro-dev libcairo-dev libpango1.0-dev libfreetype6-dev libltdl-dev libfontforge-dev python-imaging wkhtmltopdf
before_script: before_script:
- cmake -DENABLE_SVG=ON . - cmake -DENABLE_SVG=ON .
script: script:

View File

@ -143,9 +143,9 @@ void ArgParser::parse(int argc, char ** argv) const
void ArgParser::show_usage(ostream & out) const void ArgParser::show_usage(ostream & out) const
{ {
for(auto iter = arg_entries.begin(); iter != arg_entries.end(); ++iter) for(auto & entry : arg_entries)
{ {
(*iter)->show_usage(out); entry->show_usage(out);
} }
} }

View File

@ -18,34 +18,34 @@
namespace pdf2htmlEX { namespace pdf2htmlEX {
BackgroundRenderer * BackgroundRenderer::getBackgroundRenderer(const std::string & format, HTMLRenderer * html_renderer, const Param & param) std::unique_ptr<BackgroundRenderer> BackgroundRenderer::getBackgroundRenderer(const std::string & format, HTMLRenderer * html_renderer, const Param & param)
{ {
#ifdef ENABLE_LIBPNG #ifdef ENABLE_LIBPNG
if(format == "png") if(format == "png")
{ {
return new SplashBackgroundRenderer(format, html_renderer, param); return std::unique_ptr<BackgroundRenderer>(new SplashBackgroundRenderer(format, html_renderer, param));
} }
#endif #endif
#ifdef ENABLE_LIBJPEG #ifdef ENABLE_LIBJPEG
if(format == "jpg") if(format == "jpg")
{ {
return new SplashBackgroundRenderer(format, html_renderer, param); return std::unique_ptr<BackgroundRenderer>(new SplashBackgroundRenderer(format, html_renderer, param));
} }
#endif #endif
#if ENABLE_SVG #if ENABLE_SVG
if (format == "svg") if (format == "svg")
{ {
return new CairoBackgroundRenderer(html_renderer, param); return std::unique_ptr<BackgroundRenderer>(new CairoBackgroundRenderer(html_renderer, param));
} }
#endif #endif
return nullptr; return nullptr;
} }
BackgroundRenderer * BackgroundRenderer::getFallbackBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param) std::unique_ptr<BackgroundRenderer> BackgroundRenderer::getFallbackBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param)
{ {
if (param.bg_format == "svg" && param.svg_node_count_limit >= 0) if (param.bg_format == "svg" && param.svg_node_count_limit >= 0)
return new SplashBackgroundRenderer("", html_renderer, param); return std::unique_ptr<BackgroundRenderer>(new SplashBackgroundRenderer("", html_renderer, param));
return nullptr; return nullptr;
} }

View File

@ -24,10 +24,10 @@ class BackgroundRenderer
{ {
public: public:
// return nullptr upon failure // return nullptr upon failure
static BackgroundRenderer * getBackgroundRenderer(const std::string & format, HTMLRenderer * html_renderer, const Param & param); static std::unique_ptr<BackgroundRenderer> getBackgroundRenderer(const std::string & format, HTMLRenderer * html_renderer, const Param & param);
// Return a fallback bg renderer according to param.bg_format. // Return a fallback bg renderer according to param.bg_format.
// Currently only svg bg format might need a bitmap fallback. // Currently only svg bg format might need a bitmap fallback.
static BackgroundRenderer * getFallbackBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param); static std::unique_ptr<BackgroundRenderer> getFallbackBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param);
BackgroundRenderer() {} BackgroundRenderer() {}
virtual ~BackgroundRenderer() {} virtual ~BackgroundRenderer() {}

View File

@ -34,11 +34,11 @@ CairoBackgroundRenderer::CairoBackgroundRenderer(HTMLRenderer * html_renderer, c
CairoBackgroundRenderer::~CairoBackgroundRenderer() CairoBackgroundRenderer::~CairoBackgroundRenderer()
{ {
for(auto itr = bitmaps_ref_count.begin(); itr != bitmaps_ref_count.end(); ++itr) for(auto const& p : bitmaps_ref_count)
{ {
if (itr->second == 0) if (p.second == 0)
{ {
html_renderer->tmp_files.add(this->build_bitmap_path(itr->first)); html_renderer->tmp_files.add(this->build_bitmap_path(p.first));
} }
} }
} }
@ -186,8 +186,8 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
} }
// the svg file is actually used, so add its bitmaps' ref count. // the svg file is actually used, so add its bitmaps' ref count.
for (auto itr = bitmaps_in_current_page.begin(); itr != bitmaps_in_current_page.end(); itr++) for (auto id : bitmaps_in_current_page)
++bitmaps_ref_count[*itr]; ++bitmaps_ref_count[id];
return true; return true;
} }

View File

@ -10,6 +10,7 @@
#include <unordered_map> #include <unordered_map>
#include <cstdint> #include <cstdint>
#include <fstream> #include <fstream>
#include <memory>
#include <OutputDev.h> #include <OutputDev.h>
#include <GfxState.h> #include <GfxState.h>
@ -40,9 +41,8 @@
namespace pdf2htmlEX { namespace pdf2htmlEX {
class HTMLRenderer : public OutputDev struct HTMLRenderer : OutputDev
{ {
public:
HTMLRenderer(const Param & param); HTMLRenderer(const Param & param);
virtual ~HTMLRenderer(); virtual ~HTMLRenderer();
@ -149,7 +149,7 @@ public:
// Does not fail on out-of-bound conditions, but return false. // Does not fail on out-of-bound conditions, but return false.
bool is_char_covered(int index); bool is_char_covered(int index);
// Currently drawn char (glyph) count in current page. // Currently drawn char (glyph) count in current page.
int get_char_count() { return (int)covered_text_detecor.get_chars_covered().size(); } int get_char_count() { return (int)covered_text_detector.get_chars_covered().size(); }
protected: protected:
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
@ -304,9 +304,9 @@ protected:
} new_line_state; } new_line_state;
// for font reencoding // for font reencoding
int32_t * cur_mapping; std::vector<int32_t> cur_mapping;
char ** cur_mapping2; std::vector<char*> cur_mapping2;
int * width_list; std::vector<int> width_list; // width of each char
Preprocessor preprocessor; Preprocessor preprocessor;
@ -321,8 +321,8 @@ protected:
#if ENABLE_SVG #if ENABLE_SVG
friend class CairoBackgroundRenderer; // ugly! friend class CairoBackgroundRenderer; // ugly!
#endif #endif
BackgroundRenderer * bg_renderer;
BackgroundRenderer * fallback_bg_renderer; std::unique_ptr<BackgroundRenderer> bg_renderer, fallback_bg_renderer;
struct { struct {
std::ofstream fs; std::ofstream fs;
@ -333,7 +333,7 @@ protected:
static const std::string MANIFEST_FILENAME; static const std::string MANIFEST_FILENAME;
CoveredTextDetector covered_text_detecor; CoveredTextDetector covered_text_detector;
DrawingTracer tracer; DrawingTracer tracer;
}; };

View File

@ -394,8 +394,8 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
GfxCIDFont * font_cid = nullptr; GfxCIDFont * font_cid = nullptr;
string suffix = get_suffix(filepath); string suffix = get_suffix(filepath);
for(auto iter = suffix.begin(); iter != suffix.end(); ++iter) for(auto & c : suffix)
*iter = tolower(*iter); c = tolower(c);
/* /*
* if parm->tounicode is 0, try the provided tounicode map first * if parm->tounicode is 0, try the provided tounicode map first
@ -483,7 +483,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
unordered_set<string> nameset; unordered_set<string> nameset;
bool name_conflict_warned = false; bool name_conflict_warned = false;
memset(cur_mapping2, 0, 0x100 * sizeof(char*)); std::fill(cur_mapping2.begin(), cur_mapping2.end(), (char*)nullptr);
for(int i = 0; i < 256; ++i) for(int i = 0; i < 256; ++i)
{ {
@ -512,7 +512,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
} }
} }
ffw_reencode_raw2(cur_mapping2, 256, 0); ffw_reencode_raw2(cur_mapping2.data(), 256, 0);
} }
} }
else else
@ -576,8 +576,8 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
bool name_conflict_warned = false; bool name_conflict_warned = false;
auto ctu = font->getToUnicode(); auto ctu = font->getToUnicode();
memset(cur_mapping, -1, 0x10000 * sizeof(*cur_mapping)); std::fill(cur_mapping.begin(), cur_mapping.end(), -1);
memset(width_list, -1, 0x10000 * sizeof(*width_list)); std::fill(width_list.begin(), width_list.end(), -1);
if(code2GID) if(code2GID)
maxcode = min<int>(maxcode, code2GID_len - 1); maxcode = min<int>(maxcode, code2GID_len - 1);
@ -639,9 +639,8 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
retried = true; retried = true;
codeset.clear(); codeset.clear();
info.use_tounicode = false; info.use_tounicode = false;
//TODO: constant for the length std::fill(cur_mapping.begin(), cur_mapping.end(), -1);
memset(cur_mapping, -1, 0x10000 * sizeof(*cur_mapping)); std::fill(width_list.begin(), width_list.end(), -1);
memset(width_list, -1, 0x10000 * sizeof(*width_list));
cur_code = -1; cur_code = -1;
if(param.debug) if(param.debug)
{ {
@ -700,9 +699,9 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
} }
} }
ffw_set_widths(width_list, max_key + 1, param.stretch_narrow_glyph, param.squeeze_wide_glyph); ffw_set_widths(width_list.data(), max_key + 1, param.stretch_narrow_glyph, param.squeeze_wide_glyph);
ffw_reencode_raw(cur_mapping, max_key + 1, 1); ffw_reencode_raw(cur_mapping.data(), max_key + 1, 1);
// In some space offsets in HTML, we insert a ' ' there in order to improve text copy&paste // In some space offsets in HTML, we insert a ' ' there in order to improve text copy&paste
// We need to make sure that ' ' is in the font, otherwise it would be very ugly if you select the text // We need to make sure that ' ' is in the font, otherwise it would be very ugly if you select the text
@ -1061,8 +1060,8 @@ void HTMLRenderer::export_local_font(const FontInfo & info, GfxFont * font, cons
f_css.fs << "font-family:" << ((cssfont == "") ? (original_font_name + "," + general_font_family(font)) : cssfont) << ";"; f_css.fs << "font-family:" << ((cssfont == "") ? (original_font_name + "," + general_font_family(font)) : cssfont) << ";";
string fn = original_font_name; string fn = original_font_name;
for(auto iter = fn.begin(); iter != fn.end(); ++iter) for(auto & c : fn)
*iter = tolower(*iter); c = tolower(c);
if(font->isBold() || (fn.find("bold") != string::npos)) if(font->isBold() || (fn.find("bold") != string::npos))
f_css.fs << "font-weight:bold;"; f_css.fs << "font-weight:bold;";

View File

@ -3,7 +3,7 @@
* *
* Handling general stuffs * Handling general stuffs
* *
* Copyright (C) 2012,2013 Lu Wang <coolwanglu@gmail.com> * Copyright (C) 2012,2013,2014 Lu Wang <coolwanglu@gmail.com>
*/ */
#include <cstdio> #include <cstdio>
@ -56,9 +56,10 @@ HTMLRenderer::HTMLRenderer(const Param & param)
} }
ffw_init(param.debug); ffw_init(param.debug);
cur_mapping = new int32_t [0x10000];
cur_mapping2 = new char* [0x100]; cur_mapping.resize(0x10000);
width_list = new int [0x10000]; cur_mapping2.resize(0x100);
width_list.resize(0x10000);
/* /*
* For these states, usually the error will not be accumulated * For these states, usually the error will not be accumulated
@ -80,19 +81,16 @@ HTMLRenderer::HTMLRenderer(const Param & param)
all_manager.bottom .set_eps(EPS); all_manager.bottom .set_eps(EPS);
tracer.on_char_drawn = tracer.on_char_drawn =
[this](double * box) { covered_text_detecor.add_char_bbox(box); }; [this](double * box) { covered_text_detector.add_char_bbox(box); };
tracer.on_char_clipped = tracer.on_char_clipped =
[this](double * box, bool partial) { covered_text_detecor.add_char_bbox_clipped(box, partial); }; [this](double * box, bool partial) { covered_text_detector.add_char_bbox_clipped(box, partial); };
tracer.on_non_char_drawn = tracer.on_non_char_drawn =
[this](double * box) { covered_text_detecor.add_non_char_bbox(box); }; [this](double * box) { covered_text_detector.add_non_char_bbox(box); };
} }
HTMLRenderer::~HTMLRenderer() HTMLRenderer::~HTMLRenderer()
{ {
ffw_finalize(); ffw_finalize();
delete [] cur_mapping;
delete [] cur_mapping2;
delete [] width_list;
} }
void HTMLRenderer::process(PDFDoc *doc) void HTMLRenderer::process(PDFDoc *doc)
@ -106,8 +104,6 @@ void HTMLRenderer::process(PDFDoc *doc)
/////////////////// ///////////////////
// Process pages // Process pages
bg_renderer = nullptr;
fallback_bg_renderer = nullptr;
if(param.process_nontext) if(param.process_nontext)
{ {
bg_renderer = BackgroundRenderer::getBackgroundRenderer(param.bg_format, this, param); bg_renderer = BackgroundRenderer::getBackgroundRenderer(param.bg_format, this, param);
@ -132,6 +128,7 @@ void HTMLRenderer::process(PDFDoc *doc)
if(param.split_pages) if(param.split_pages)
{ {
// copy the string out, since we will reuse the buffer soon
string filled_template_filename = (char*)str_fmt(param.page_filename.c_str(), i); string filled_template_filename = (char*)str_fmt(param.page_filename.c_str(), i);
auto page_fn = str_fmt("%s/%s", param.dest_dir.c_str(), filled_template_filename.c_str()); auto page_fn = str_fmt("%s/%s", param.dest_dir.c_str(), filled_template_filename.c_str());
f_curpage = new ofstream((char*)page_fn, ofstream::binary); f_curpage = new ofstream((char*)page_fn, ofstream::binary);
@ -167,16 +164,8 @@ void HTMLRenderer::process(PDFDoc *doc)
post_process(); post_process();
if(bg_renderer) bg_renderer = nullptr;
{ fallback_bg_renderer = nullptr;
delete bg_renderer;
bg_renderer = nullptr;
}
if(fallback_bg_renderer)
{
delete fallback_bg_renderer;
fallback_bg_renderer = nullptr;
}
cerr << endl; cerr << endl;
} }
@ -188,7 +177,7 @@ void HTMLRenderer::setDefaultCTM(double *ctm)
void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref) void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
{ {
covered_text_detecor.reset(); covered_text_detector.reset();
tracer.reset(state); tracer.reset(state);
this->pageNum = pageNum; this->pageNum = pageNum;
@ -235,8 +224,10 @@ void HTMLRenderer::endPage() {
if(param.process_nontext) if(param.process_nontext)
{ {
if (bg_renderer->render_page(cur_doc, pageNum)) if (bg_renderer->render_page(cur_doc, pageNum))
{
bg_renderer->embed_image(pageNum); bg_renderer->embed_image(pageNum);
else if (fallback_bg_renderer != nullptr) }
else if (fallback_bg_renderer)
{ {
if (fallback_bg_renderer->render_page(cur_doc, pageNum)) if (fallback_bg_renderer->render_page(cur_doc, pageNum))
fallback_bg_renderer->embed_image(pageNum); fallback_bg_renderer->embed_image(pageNum);
@ -257,18 +248,20 @@ void HTMLRenderer::endPage() {
// dump info for js // dump info for js
// TODO: create a function for this // TODO: create a function for this
// BE CAREFUL WITH ESCAPES // BE CAREFUL WITH ESCAPES
(*f_curpage) << "<div class=\"" << CSS::PAGE_DATA_CN << "\" data-data='{";
//default CTM
(*f_curpage) << "\"ctm\":[";
for(int i = 0; i < 6; ++i)
{ {
if(i > 0) (*f_curpage) << ","; (*f_curpage) << "<div class=\"" << CSS::PAGE_DATA_CN << "\" data-data='{";
(*f_curpage) << round(default_ctm[i]);
}
(*f_curpage) << "]";
(*f_curpage) << "}'></div>"; //default CTM
(*f_curpage) << "\"ctm\":[";
for(int i = 0; i < 6; ++i)
{
if(i > 0) (*f_curpage) << ",";
(*f_curpage) << round(default_ctm[i]);
}
(*f_curpage) << "]";
(*f_curpage) << "}'></div>";
}
// close page // close page
(*f_curpage) << "</div>" << endl; (*f_curpage) << "</div>" << endl;
@ -388,7 +381,6 @@ void HTMLRenderer::post_process(void)
{ {
dump_css(); dump_css();
// close files if they opened // close files if they opened
// it's better to brace single liner LLVM complains
if (param.process_outline) if (param.process_outline)
{ {
f_outline.fs.close(); f_outline.fs.close();
@ -542,7 +534,6 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string &
string fn = get_filename(path); string fn = get_filename(path);
string suffix = (type == "") ? get_suffix(fn) : type; string suffix = (type == "") ? get_suffix(fn) : type;
// TODO
auto iter = EMBED_STRING_MAP.find(suffix); auto iter = EMBED_STRING_MAP.find(suffix);
if(iter == EMBED_STRING_MAP.end()) if(iter == EMBED_STRING_MAP.end())
{ {

View File

@ -153,7 +153,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
bool HTMLRenderer::is_char_covered(int index) bool HTMLRenderer::is_char_covered(int index)
{ {
auto covered = covered_text_detecor.get_chars_covered(); auto covered = covered_text_detector.get_chars_covered();
if (index < 0 || index >= (int)covered.size()) if (index < 0 || index >= (int)covered.size())
{ {
std::cerr << "Warning: HTMLRenderer::is_char_covered: index out of bound: " std::cerr << "Warning: HTMLRenderer::is_char_covered: index out of bound: "

View File

@ -23,10 +23,8 @@ HTMLTextPage::HTMLTextPage(const Param & param, AllStateManager & all_manager)
HTMLTextPage::~HTMLTextPage() HTMLTextPage::~HTMLTextPage()
{ {
for(auto iter = text_lines.begin(); iter != text_lines.end(); ++iter) for(auto p : text_lines)
{ delete p;
delete (*iter);
}
} }
void HTMLTextPage::dump_text(ostream & out) void HTMLTextPage::dump_text(ostream & out)
@ -35,12 +33,12 @@ void HTMLTextPage::dump_text(ostream & out)
{ {
// text lines may be split during optimization, collect them // text lines may be split during optimization, collect them
std::vector<HTMLTextLine*> new_text_lines; std::vector<HTMLTextLine*> new_text_lines;
for(auto iter = text_lines.begin(); iter != text_lines.end(); ++iter) for(auto p : text_lines)
(*iter)->optimize(new_text_lines); p->optimize(new_text_lines);
std::swap(text_lines, new_text_lines); std::swap(text_lines, new_text_lines);
} }
for(auto iter = text_lines.begin(); iter != text_lines.end(); ++iter) for(auto p : text_lines)
(*iter)->prepare(); p->prepare();
if(param.optimize_text) if(param.optimize_text)
optimize(); optimize();

View File

@ -36,8 +36,8 @@ Preprocessor::Preprocessor(const Param & param)
Preprocessor::~Preprocessor(void) Preprocessor::~Preprocessor(void)
{ {
for(auto iter = code_maps.begin(); iter != code_maps.end(); ++iter) for(auto & p : code_maps)
delete [] iter->second; delete [] p.second;
} }
void Preprocessor::process(PDFDoc * doc) void Preprocessor::process(PDFDoc * doc)

View File

@ -59,19 +59,19 @@ public:
} }
void dump_css(std::ostream & out) { void dump_css(std::ostream & out) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
out << "." << imp->get_css_class_name() << iter->second << "{"; out << "." << imp->get_css_class_name() << p.second << "{";
imp->dump_value(out, iter->first); imp->dump_value(out, p.first);
out << "}" << std::endl; out << "}" << std::endl;
} }
} }
void dump_print_css(std::ostream & out, double scale) { void dump_print_css(std::ostream & out, double scale) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
out << "." << imp->get_css_class_name() << iter->second << "{"; out << "." << imp->get_css_class_name() << p.second << "{";
imp->dump_print_value(out, iter->first, scale); imp->dump_print_value(out, p.first, scale);
out << "}" << std::endl; out << "}" << std::endl;
} }
} }
@ -109,10 +109,10 @@ public:
} }
void dump_css(std::ostream & out) { void dump_css(std::ostream & out) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
out << "." << imp->get_css_class_name() << iter->second << "{"; out << "." << imp->get_css_class_name() << p.second << "{";
imp->dump_value(out, iter->first); imp->dump_value(out, p.first);
out << "}" << std::endl; out << "}" << std::endl;
} }
} }
@ -166,10 +166,10 @@ public:
imp->dump_transparent(out); imp->dump_transparent(out);
out << "}" << std::endl; out << "}" << std::endl;
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
out << "." << imp->get_css_class_name() << iter->second << "{"; out << "." << imp->get_css_class_name() << p.second << "{";
imp->dump_value(out, iter->first); imp->dump_value(out, p.first);
out << "}" << std::endl; out << "}" << std::endl;
} }
} }
@ -307,15 +307,15 @@ public:
auto prefixes = {"", "-ms-", "-webkit-"}; auto prefixes = {"", "-ms-", "-webkit-"};
if(tm_equal(m, ID_MATRIX, 4)) if(tm_equal(m, ID_MATRIX, 4))
{ {
for(auto iter = prefixes.begin(); iter != prefixes.end(); ++iter) for(auto & s : prefixes)
out << *iter << "transform:none;"; out << s << "transform:none;";
} }
else else
{ {
for(auto iter = prefixes.begin(); iter != prefixes.end(); ++iter) for(auto & s : prefixes)
{ {
// PDF use a different coordinate system from Web // PDF use a different coordinate system from Web
out << *iter << "transform:matrix(" out << s << "transform:matrix("
<< round(m[0]) << ',' << round(m[0]) << ','
<< round(-m[1]) << ',' << round(-m[1]) << ','
<< round(-m[2]) << ',' << round(-m[2]) << ','
@ -332,10 +332,10 @@ public:
static const char * get_css_class_name (void) { return CSS::FILL_COLOR_CN; } static const char * get_css_class_name (void) { return CSS::FILL_COLOR_CN; }
/* override base's method, as we need some workaround in CSS */ /* override base's method, as we need some workaround in CSS */
void dump_css(std::ostream & out) { void dump_css(std::ostream & out) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
out << "." << get_css_class_name() << iter->second out << "." << get_css_class_name() << p.second
<< "{color:" << iter->first << ";}" << std::endl; << "{color:" << p.first << ";}" << std::endl;
} }
} }
}; };
@ -348,24 +348,24 @@ public:
void dump_css(std::ostream & out) { void dump_css(std::ostream & out) {
// normal CSS // normal CSS
out << "." << get_css_class_name() << CSS::INVALID_ID << "{text-shadow:none;}" << std::endl; out << "." << get_css_class_name() << CSS::INVALID_ID << "{text-shadow:none;}" << std::endl;
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
// TODO: take the stroke width from the graphics state, // TODO: take the stroke width from the graphics state,
// currently using 0.015em as a good default // currently using 0.015em as a good default
out << "." << get_css_class_name() << iter->second << "{text-shadow:" out << "." << get_css_class_name() << p.second << "{text-shadow:"
<< "-0.015em 0 " << iter->first << "," << "-0.015em 0 " << p.first << ","
<< "0 0.015em " << iter->first << "," << "0 0.015em " << p.first << ","
<< "0.015em 0 " << iter->first << "," << "0.015em 0 " << p.first << ","
<< "0 -0.015em " << iter->first << ";" << "0 -0.015em " << p.first << ";"
<< "}" << std::endl; << "}" << std::endl;
} }
// webkit // webkit
out << CSS::WEBKIT_ONLY << "{" << std::endl; out << CSS::WEBKIT_ONLY << "{" << std::endl;
out << "." << get_css_class_name() << CSS::INVALID_ID << "{-webkit-text-stroke:0px transparent;}" << std::endl; out << "." << get_css_class_name() << CSS::INVALID_ID << "{-webkit-text-stroke:0px transparent;}" << std::endl;
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
out << "." << get_css_class_name() << iter->second out << "." << get_css_class_name() << p.second
<< "{-webkit-text-stroke:0.015em " << iter->first << ";text-shadow:none;}" << std::endl; << "{-webkit-text-stroke:0.015em " << p.first << ";text-shadow:none;}" << std::endl;
} }
out << "}" << std::endl; out << "}" << std::endl;
} }
@ -385,20 +385,20 @@ public:
} }
void dump_css(std::ostream & out) { void dump_css(std::ostream & out) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
const auto & s = iter->second; const auto & s = p.second;
out << "." << CSS::PAGE_CONTENT_BOX_CN << iter->first << "{"; out << "." << CSS::PAGE_CONTENT_BOX_CN << p.first << "{";
out << "background-size:" << round(s.first) << "px " << round(s.second) << "px;"; out << "background-size:" << round(s.first) << "px " << round(s.second) << "px;";
out << "}" << std::endl; out << "}" << std::endl;
} }
} }
void dump_print_css(std::ostream & out, double scale) { void dump_print_css(std::ostream & out, double scale) {
for(auto iter = value_map.begin(); iter != value_map.end(); ++iter) for(auto & p : value_map)
{ {
const auto & s = iter->second; const auto & s = p.second;
out << "." << CSS::PAGE_CONTENT_BOX_CN << iter->first << "{"; out << "." << CSS::PAGE_CONTENT_BOX_CN << p.first << "{";
out << "background-size:" << round(s.first * scale) << "pt " << round(s.second * scale) << "pt;"; out << "background-size:" << round(s.first * scale) << "pt " << round(s.second * scale) << "pt;";
out << "}" << std::endl; out << "}" << std::endl;
} }

View File

@ -46,8 +46,9 @@ double TmpFiles::get_total_size() const
{ {
double total_size = 0; double total_size = 0;
struct stat st; struct stat st;
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) { for(auto & fn : tmp_files)
stat(iter->c_str(), &st); {
stat(fn.c_str(), &st);
total_size += st.st_size; total_size += st.st_size;
} }
@ -60,9 +61,8 @@ void TmpFiles::clean()
if(!param.clean_tmp) if(!param.clean_tmp)
return; return;
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) for(auto & fn : tmp_files)
{ {
const string & fn = *iter;
remove(fn.c_str()); remove(fn.c_str());
if(param.debug) if(param.debug)
cerr << "Remove temporary file: " << fn << endl; cerr << "Remove temporary file: " << fn << endl;

View File

@ -131,9 +131,9 @@ void writeURL(ostream & out, const string & s)
void writeJSON(ostream & out, const string & s) void writeJSON(ostream & out, const string & s)
{ {
for(auto iter = s.begin(); iter != s.end(); ++iter) for(auto c : s)
{ {
switch (*iter) switch (c)
{ {
case '\\': out << "\\\\"; break; case '\\': out << "\\\\"; break;
case '"': out << "\\\""; break; case '"': out << "\\\""; break;
@ -144,16 +144,15 @@ void writeJSON(ostream & out, const string & s)
case '\n': out << "\\n"; break; case '\n': out << "\\n"; break;
case '\r': out << "\\r"; break; case '\r': out << "\\r"; break;
case '\t': out << "\\t"; break; case '\t': out << "\\t"; break;
default: out << *iter; break; default: out << c; break;
} }
} }
} }
void writeAttribute(std::ostream & out, const std::string & s) void writeAttribute(std::ostream & out, const std::string & s)
{ {
for (auto iter = s.begin(); iter != s.end(); ++iter) for (auto c : s)
{ {
char c = *iter;
switch(c) switch(c)
{ {
case '&': case '&':

View File

@ -131,8 +131,8 @@ string get_suffix(const string & path)
else else
{ {
string s = fn.substr(idx); string s = fn.substr(idx);
for(auto iter = s.begin(); iter != s.end(); ++iter) for(auto & c : s)
*iter = tolower(*iter); c = tolower(c);
return s; return s;
} }
} }