mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
fix color bug; working on image output
This commit is contained in:
parent
cb1e3406d6
commit
b038322e61
@ -14,8 +14,8 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
|||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-function")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-function")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
|
||||||
|
|
||||||
add_executable(pdftohtmlEX src/pdftohtmlEX.cc src/HTMLRenderer.cc src/HTMLRenderer.h src/BackgroundRenderer.cc src/BackgroundRenderer.h src/Consts.h src/Consts.cc src/util.h)
|
add_executable(pdftohtmlEX src/pdftohtmlEX.cc src/HTMLRenderer.cc src/HTMLRenderer.h src/BackgroundRenderer.cc src/BackgroundRenderer.h src/Consts.h src/Consts.cc src/util.h)
|
||||||
target_link_libraries(pdftohtmlEX poppler boost_program_options)
|
target_link_libraries(pdftohtmlEX poppler boost_program_options)
|
||||||
|
@ -14,14 +14,19 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
// for gil bug
|
||||||
|
const int *int_p_NULL = nullptr;
|
||||||
|
#include <boost/gil/gil_all.hpp>
|
||||||
|
#include <boost/gil/extension/io/png_dynamic_io.hpp>
|
||||||
|
|
||||||
#include <GfxFont.h>
|
#include <GfxFont.h>
|
||||||
|
#include <CharCodeToUnicode.h>
|
||||||
#include <fofi/FoFiType1C.h>
|
#include <fofi/FoFiType1C.h>
|
||||||
#include <fofi/FoFiTrueType.h>
|
#include <fofi/FoFiTrueType.h>
|
||||||
#include <splash/SplashBitmap.h>
|
#include <splash/SplashBitmap.h>
|
||||||
#include <CharCodeToUnicode.h>
|
|
||||||
|
|
||||||
#include "HTMLRenderer.h"
|
#include "HTMLRenderer.h"
|
||||||
#include "BackgroundRenderer.h"
|
#include "BackgroundRenderer.h"
|
||||||
@ -51,6 +56,7 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
|||||||
,html_fout(param->output_filename.c_str(), ofstream::binary)
|
,html_fout(param->output_filename.c_str(), ofstream::binary)
|
||||||
,allcss_fout("all.css")
|
,allcss_fout("all.css")
|
||||||
,fontscript_fout(TMP_DIR+"/convert.pe")
|
,fontscript_fout(TMP_DIR+"/convert.pe")
|
||||||
|
,image_count(0)
|
||||||
,param(param)
|
,param(param)
|
||||||
{
|
{
|
||||||
// install default font & size
|
// install default font & size
|
||||||
@ -367,6 +373,41 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
|
|||||||
draw_ty += dy;
|
draw_ty += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HTMLRenderer::drawImage(GfxState * state, Object * ref, Stream * str, int width, int height, GfxImageColorMap * colorMap, GBool interpolate, int *maskColors, GBool inlineImg)
|
||||||
|
{
|
||||||
|
boost::gil::rgb16_image_t img(width, height);
|
||||||
|
auto imgview = view(img);
|
||||||
|
auto loc = imgview.xy_at(0,0);
|
||||||
|
|
||||||
|
ImageStream * img_stream = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
|
||||||
|
img_stream->reset();
|
||||||
|
|
||||||
|
for(int i = 0; i < height; ++i)
|
||||||
|
{
|
||||||
|
auto p = img_stream->getLine();
|
||||||
|
for(int j = 0; j < width; ++j)
|
||||||
|
{
|
||||||
|
GfxRGB rgb;
|
||||||
|
colorMap->getRGB(p, &rgb);
|
||||||
|
|
||||||
|
*loc = boost::gil::rgb16_pixel_t(rgb.r, rgb.g, rgb.b);
|
||||||
|
|
||||||
|
p += colorMap->getNumPixelComps();
|
||||||
|
|
||||||
|
++ loc.x();
|
||||||
|
}
|
||||||
|
|
||||||
|
loc = imgview.xy_at(0, i+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::gil::png_write_view((boost::format("i%|1$x|.png")%image_count).str(), imgview);
|
||||||
|
|
||||||
|
img_stream->close();
|
||||||
|
delete img_stream;
|
||||||
|
|
||||||
|
++ image_count;
|
||||||
|
}
|
||||||
|
|
||||||
// The font installation code is stolen from PSOutputDev.cc in poppler
|
// The font installation code is stolen from PSOutputDev.cc in poppler
|
||||||
|
|
||||||
long long HTMLRenderer::install_font(GfxFont * font)
|
long long HTMLRenderer::install_font(GfxFont * font)
|
||||||
@ -565,6 +606,8 @@ err:
|
|||||||
|
|
||||||
void HTMLRenderer::install_embedded_font(GfxFont * font, const std::string & suffix, long long fn_id)
|
void HTMLRenderer::install_embedded_font(GfxFont * font, const std::string & suffix, long long fn_id)
|
||||||
{
|
{
|
||||||
|
// TODO Should use standard way to handle CID fonts
|
||||||
|
|
||||||
std::string fn = (boost::format("f%|1$x|") % fn_id).str();
|
std::string fn = (boost::format("f%|1$x|") % fn_id).str();
|
||||||
|
|
||||||
fontscript_fout << boost::format("Open(\"%1%/%2%%3%\",1)") % TMP_DIR % fn % suffix << endl;
|
fontscript_fout << boost::format("Open(\"%1%/%2%%3%\",1)") % TMP_DIR % fn % suffix << endl;
|
||||||
@ -585,10 +628,17 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const std::string & suf
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
maxcode = 0xffff;
|
maxcode = 0xffff;
|
||||||
fontscript_fout << boost::format("Reencode(\"original\")") << endl;
|
if(suffix != ".ttf")
|
||||||
int len;
|
{
|
||||||
// code2GID has been stored for embedded CID fonts
|
fontscript_fout << "CIDFlatten()" << endl;
|
||||||
code2GID = dynamic_cast<GfxCIDFont*>(font)->getCodeToGIDMap(nullptr, &len);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fontscript_fout << boost::format("Reencode(\"original\")") << endl;
|
||||||
|
int len;
|
||||||
|
// code2GID has been stored for embedded CID fonts
|
||||||
|
code2GID = dynamic_cast<GfxCIDFont*>(font)->getCodeToGIDMap(nullptr, &len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(maxcode > 0)
|
if(maxcode > 0)
|
||||||
@ -822,7 +872,7 @@ void HTMLRenderer::export_transform_matrix (long long tm_id, const double * tm)
|
|||||||
void HTMLRenderer::export_color(long long color_id, const GfxRGB * rgb)
|
void HTMLRenderer::export_color(long long color_id, const GfxRGB * rgb)
|
||||||
{
|
{
|
||||||
allcss_fout << boost::format(".c%|1$x|{color:rgb(%2%,%3%,%4%);}")
|
allcss_fout << boost::format(".c%|1$x|{color:rgb(%2%,%3%,%4%);}")
|
||||||
% color_id % rgb->r % rgb->g % rgb->b;
|
% color_id % (int)colToByte(rgb->r) % (int)colToByte(rgb->g) % (int)colToByte(rgb->b);
|
||||||
allcss_fout << endl;
|
allcss_fout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +90,10 @@ class HTMLRenderer : public OutputDev
|
|||||||
virtual void updateTextShift(GfxState * state, double shift);
|
virtual void updateTextShift(GfxState * state, double shift);
|
||||||
virtual void updateFillColor(GfxState * state);
|
virtual void updateFillColor(GfxState * state);
|
||||||
|
|
||||||
//----- text drawing
|
|
||||||
virtual void drawString(GfxState * state, GooString * s);
|
virtual void drawString(GfxState * state, GooString * s);
|
||||||
|
|
||||||
|
virtual void drawImage(GfxState * state, Object * ref, Stream * str, int width, int height, GfxImageColorMap * colorMap, GBool interpolate, int *maskColors, GBool inlineImg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void close_cur_line();
|
void close_cur_line();
|
||||||
|
|
||||||
@ -135,8 +136,6 @@ class HTMLRenderer : public OutputDev
|
|||||||
double pageWidth ;
|
double pageWidth ;
|
||||||
double pageHeight ;
|
double pageHeight ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// state tracking when processing pdf
|
// state tracking when processing pdf
|
||||||
void check_state_change(GfxState * state);
|
void check_state_change(GfxState * state);
|
||||||
void reset_state_track();
|
void reset_state_track();
|
||||||
@ -242,6 +241,8 @@ class HTMLRenderer : public OutputDev
|
|||||||
};
|
};
|
||||||
map<Color, long long> color_map;
|
map<Color, long long> color_map;
|
||||||
|
|
||||||
|
int image_count;
|
||||||
|
|
||||||
const Param * param;
|
const Param * param;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <iostream>
|
||||||
#include <goo/GooString.h>
|
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
|
||||||
|
#include <goo/GooString.h>
|
||||||
|
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include "PDFDoc.h"
|
#include "PDFDoc.h"
|
||||||
#include "PDFDocFactory.h"
|
#include "PDFDocFactory.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user