mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
9ed21007e5
* Show header in font map files * fix a usage of unique_ptr with array * Added '--quiet' argument to hide progress messages (resolves #503) * Revert cout messages to cerr (see #622) * bump version * fix build; fix some coverity warnings * Many bug fixes and improvements, including: - Incorporated latest Cairo files from cairo-0.15.2 - Moved build to out-of-source - Added clean script - Rewritten correct_text_visibility option to improve accuracy - Transparent characters drawn on background layer - Improved bad unicode detection * Many bug fixes and improvements, including: - Incorporated latest Cairo files from cairo-0.15.2 - Moved build to out-of-source - Added clean script - Rewritten correct_text_visibility option to improve accuracy - Transparent characters drawn on background layer - Improved bad unicode detection * Rationlise DPI to single number. Implement actual_dpi - clamp maximum background image size in cases of huge PDF pages * DPI fixes - increase DPI when partially covered text to covered-text-dpi Add font-style italic for oblique fonts Reduce char bbox for occlusion tests * Don't shrink bbox - not required if zoom=25 used * Ignore occlusion from stroke/fill with opacity < 0.5 Better compute char bbox for occlusion Use 10% inset for char bbox for occlusion Back out adding font-weight: bold to potentially bold fonts Fix bug to ensure CID ascent/descent matches subfont values * Removed zero char logging * Remove forced italic - missing italic is due to fontforge bug which needs fixing * Typos fixed, readme updated * Typos * Increase maximum background image width Fix private use range to avoid stupid mobile safari switching to emoji font * included -pthread switch to link included 3rdparty poppler files. * Updated files from poppler 0.59.0 and adjusted includes. * Support updated "Object" class from poppler 0.59.0
111 lines
2.6 KiB
C++
111 lines
2.6 KiB
C++
/*
|
|
* Preprocessor.cc
|
|
*
|
|
* Check used codes for each font
|
|
*
|
|
* by WangLu
|
|
* 2012.09.07
|
|
*/
|
|
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <algorithm>
|
|
|
|
#include <GfxState.h>
|
|
#include <GfxFont.h>
|
|
|
|
#include "Preprocessor.h"
|
|
#include "util/misc.h"
|
|
#include "util/const.h"
|
|
|
|
namespace pdf2htmlEX {
|
|
|
|
using std::cerr;
|
|
using std::endl;
|
|
using std::flush;
|
|
using std::max;
|
|
|
|
Preprocessor::Preprocessor(const Param & param)
|
|
: OutputDev()
|
|
, param(param)
|
|
, max_width(0)
|
|
, max_height(0)
|
|
, cur_font_id(0)
|
|
, cur_code_map(nullptr)
|
|
{ }
|
|
|
|
Preprocessor::~Preprocessor(void)
|
|
{
|
|
for(auto & p : code_maps)
|
|
delete [] p.second;
|
|
}
|
|
|
|
void Preprocessor::process(PDFDoc * doc)
|
|
{
|
|
int page_count = (param.last_page - param.first_page + 1);
|
|
for(int i = param.first_page; i <= param.last_page ; ++i)
|
|
{
|
|
if(param.quiet == 0)
|
|
cerr << "Preprocessing: " << (i - param.first_page) << "/" << page_count << '\r' << flush;
|
|
|
|
doc->displayPage(this, i, DEFAULT_DPI, DEFAULT_DPI,
|
|
0,
|
|
(!(param.use_cropbox)),
|
|
true, // crop
|
|
false, // printing
|
|
nullptr, nullptr, nullptr, nullptr);
|
|
}
|
|
if(page_count >= 0 && param.quiet == 0)
|
|
cerr << "Preprocessing: " << page_count << "/" << page_count;
|
|
|
|
if(param.quiet == 0)
|
|
cerr << endl;
|
|
}
|
|
|
|
void Preprocessor::drawChar(GfxState *state, double x, double y,
|
|
double dx, double dy,
|
|
double originX, double originY,
|
|
CharCode code, int nBytes, Unicode *u, int uLen)
|
|
{
|
|
GfxFont * font = state->getFont();
|
|
if(!font) return;
|
|
|
|
long long fn_id = hash_ref(font->getID());
|
|
|
|
if(fn_id != cur_font_id)
|
|
{
|
|
cur_font_id = fn_id;
|
|
auto p = code_maps.insert(std::make_pair(cur_font_id, (char*)nullptr));
|
|
if(p.second)
|
|
{
|
|
// this is a new font
|
|
int len = font->isCIDFont() ? 0x10000 : 0x100;
|
|
p.first->second = new char [len];
|
|
memset(p.first->second, 0, len * sizeof(char));
|
|
}
|
|
|
|
cur_code_map = p.first->second;
|
|
}
|
|
|
|
cur_code_map[code] = 1;
|
|
}
|
|
|
|
void Preprocessor::startPage(int pageNum, GfxState *state)
|
|
{
|
|
startPage(pageNum, state, nullptr);
|
|
}
|
|
|
|
void Preprocessor::startPage(int pageNum, GfxState *state, XRef * xref)
|
|
{
|
|
max_width = max<double>(max_width, state->getPageWidth());
|
|
max_height = max<double>(max_height, state->getPageHeight());
|
|
}
|
|
|
|
const char * Preprocessor::get_code_map (long long font_id) const
|
|
{
|
|
auto iter = code_maps.find(font_id);
|
|
return (iter == code_maps.end()) ? nullptr : (iter->second);
|
|
}
|
|
|
|
} // namespace pdf2htmlEX
|