mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
add FontPreprocessor.*
This commit is contained in:
parent
1eb625c4fb
commit
a0de63d85a
61
src/FontPreprocessor.cc
Normal file
61
src/FontPreprocessor.cc
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* FontPreprocessor.h
|
||||
*
|
||||
* Check used codes for each font
|
||||
*
|
||||
* by WangLu
|
||||
* 2012.09.07
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <GfxState.h>
|
||||
#include <GfxFont.h>
|
||||
|
||||
#include "FontPreprocessor.h"
|
||||
#include "util.h"
|
||||
|
||||
FontPreprocessor::FontPreprocessor(void)
|
||||
: cur_font_id(0)
|
||||
, cur_code_map(nullptr)
|
||||
{ }
|
||||
|
||||
FontPreprocessor::~FontPreprocessor(void)
|
||||
{
|
||||
for(auto & p : code_maps)
|
||||
delete [] p.second;
|
||||
}
|
||||
|
||||
void FontPreprocessor::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, 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;
|
||||
}
|
||||
|
||||
const char * FontPreprocessor::get_code_map (long long font_id) const
|
||||
{
|
||||
auto iter = code_maps.find(font_id);
|
||||
return (iter == code_maps.end()) ? nullptr : (iter->second);
|
||||
}
|
42
src/FontPreprocessor.h
Normal file
42
src/FontPreprocessor.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* FontPreprocessor.h
|
||||
*
|
||||
* Check used codes for each font
|
||||
*
|
||||
* by WangLu
|
||||
* 2012.09.07
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FONTPREPROCESSOR_H__
|
||||
#define FONTPREPROCESSOR_H__
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <OutputDev.h>
|
||||
|
||||
class FontPreprocessor : public OutputDev {
|
||||
public:
|
||||
FontPreprocessor(void);
|
||||
virtual ~FontPreprocessor(void);
|
||||
|
||||
virtual GBool upsideDown() { return gFalse; }
|
||||
virtual GBool useDrawChar() { return gTrue; }
|
||||
virtual GBool interpretType3Chars() { return gFalse; }
|
||||
virtual GBool needNonText() { return gFalse; }
|
||||
virtual void drawChar(GfxState *state, double x, double y,
|
||||
double dx, double dy,
|
||||
double originX, double originY,
|
||||
CharCode code, int nBytes, Unicode *u, int uLen);
|
||||
|
||||
const char * get_code_map (long long font_id) const;
|
||||
|
||||
protected:
|
||||
long long cur_font_id;
|
||||
char * cur_code_map;
|
||||
|
||||
std::unordered_map<long long, char*> code_maps;
|
||||
};
|
||||
|
||||
|
||||
#endif //FONTPREPROCESSOR_H__
|
Loading…
Reference in New Issue
Block a user