mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
Modifications following review from Lu. Win32 modifications are now more localized
This commit is contained in:
parent
45f9cd116b
commit
a47d42ad4b
@ -16,6 +16,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef _WIN32
|
||||
# define STAT stat
|
||||
#else
|
||||
# define STAT _stat
|
||||
#endif
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
|
||||
@ -55,20 +61,13 @@ void TmpFiles::clean()
|
||||
cerr << "Remove temporary directory: " << param.tmp_dir << endl;
|
||||
}
|
||||
|
||||
// Return the total size of the temporary files in bytes
|
||||
double TmpFiles::get_total_size() const
|
||||
{
|
||||
double total_size = 0;
|
||||
#ifndef _WIN32
|
||||
struct stat st;
|
||||
#else
|
||||
struct _stat st;
|
||||
#endif
|
||||
struct STAT st;
|
||||
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) {
|
||||
#ifndef _WIN32
|
||||
stat(iter->c_str(), &st);
|
||||
#else
|
||||
_stat(iter->c_str(), &st);
|
||||
#endif
|
||||
STAT(iter->c_str(), &st);
|
||||
total_size += st.st_size;
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ ArgParser argparser;
|
||||
#ifdef _WIN32
|
||||
# include <iomanip>
|
||||
# include <libgen.h>
|
||||
# include <direct.h>
|
||||
#endif
|
||||
|
||||
void deprecated_font_suffix(const char * dummy = nullptr)
|
||||
@ -70,11 +71,7 @@ void show_version_and_exit(const char * dummy = nullptr)
|
||||
#if ENABLE_SVG
|
||||
cerr << " cairo " << cairo_version_string() << endl;
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
cerr << "Default data-dir: " << param.data_dir << endl;
|
||||
#else
|
||||
cerr << "Default data-dir: " << PDF2HTMLEX_DATA_PATH << endl;
|
||||
#endif
|
||||
cerr << "Supported image format:";
|
||||
#ifdef ENABLE_LIBPNG
|
||||
cerr << " png";
|
||||
@ -143,7 +140,10 @@ void prepare_directories()
|
||||
|
||||
tmp_dir.erase(tmp_dir.size() - 6);
|
||||
param.tmp_dir = tmp_dir + ss.str();
|
||||
::CreateDirectory(param.tmp_dir.c_str(), NULL);
|
||||
if (mkdir(param.tmp_dir.c_str())) {
|
||||
cerr << "Cannot create temp directory (" << param.tmp_dir << "): " << strerror(errno) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ void parse_options (int argc, char **argv)
|
||||
.add("embed-image", ¶m.embed_image, 1, "embed image files into output")
|
||||
.add("embed-javascript", ¶m.embed_javascript, 1, "embed JavaScript files into output")
|
||||
.add("embed-outline", ¶m.embed_outline, 1, "embed outlines into output")
|
||||
.add("max-output-size", ¶m.max_size, -1, "maximum output size, in KB (-1 for no max)")
|
||||
.add("output-size-limit", ¶m.max_size, -1, "Limit the output size, in KB (-1 for no limit). This is only an estimate, the output may be bigger")
|
||||
.add("split-pages", ¶m.split_pages, 0, "split pages into separate files")
|
||||
.add("dest-dir", ¶m.dest_dir, ".", "specify destination directory")
|
||||
.add("css-filename", ¶m.css_filename, "", "filename of the generated css file")
|
||||
@ -211,11 +211,7 @@ void parse_options (int argc, char **argv)
|
||||
// misc.
|
||||
.add("clean-tmp", ¶m.clean_tmp, 1, "remove temporary files after conversion")
|
||||
.add("base-tmp-dir", ¶m.basetmp_dir, param.basetmp_dir, "base temporary directory - will create pdf2htmlEX-XXXXXX under it")
|
||||
#ifdef _WIN32
|
||||
.add("data-dir", ¶m.data_dir, param.data_dir, "specify data directory")
|
||||
#else
|
||||
.add("data-dir", ¶m.data_dir, PDF2HTMLEX_DATA_PATH, "specify data directory")
|
||||
#endif
|
||||
// TODO: css drawings are hidden on print, for annot links, need to fix it for other drawings
|
||||
// .add("css-draw", ¶m.css_draw, 0, "[experimental and unsupported] CSS drawing")
|
||||
.add("debug", ¶m.debug, 0, "print debugging information")
|
||||
@ -366,6 +362,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
param.basetmp_dir = "/tmp";
|
||||
param.data_dir = PDF2HTMLEX_DATA_PATH;
|
||||
#else
|
||||
{
|
||||
// Under Windows, the default data_dir is under /data in the pdf2htmlEX directory
|
||||
|
@ -19,11 +19,6 @@
|
||||
|
||||
#include "ffw.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#undef printf
|
||||
#undef vfprintf
|
||||
#endif
|
||||
|
||||
static real EPS=1e-6;
|
||||
|
||||
static inline int min(int a, int b)
|
||||
@ -64,7 +59,7 @@ void ffw_init(int debug)
|
||||
if ( default_encoding==NULL )
|
||||
default_encoding=FindOrMakeEncoding("ISO8859-1");
|
||||
if ( default_encoding==NULL )
|
||||
default_encoding=&custom; /* In case iconv is broken */
|
||||
default_encoding=&custom; /* In case iconv is broken */
|
||||
|
||||
if(!debug)
|
||||
{
|
||||
@ -172,13 +167,13 @@ void ffw_save(const char * filename)
|
||||
|
||||
int r = GenerateScript(cur_fv->sf, _filename
|
||||
, _, -1, -1, NULL, NULL, cur_fv->map, NULL, ly_fore);
|
||||
|
||||
|
||||
free(_);
|
||||
free(_filename);
|
||||
|
||||
if(!r)
|
||||
err("Cannot save font to %s\n", filename);
|
||||
}
|
||||
}
|
||||
void ffw_close(void)
|
||||
{
|
||||
FontViewClose(cur_fv);
|
||||
@ -295,8 +290,8 @@ void ffw_add_empty_char(int32_t unicode, int width)
|
||||
{
|
||||
SplineChar * sc = SFMakeChar(cur_fv->sf, cur_fv->map, cur_fv->map->enccount);
|
||||
char buffer[400];
|
||||
SCSetMetaData(sc,
|
||||
strcopy(StdGlyphName(buffer, unicode,
|
||||
SCSetMetaData(sc,
|
||||
strcopy(StdGlyphName(buffer, unicode,
|
||||
cur_fv->sf->uni_interp, cur_fv->sf->for_new_glyphs)),
|
||||
unicode, sc->comment);
|
||||
SCSynchronizeWidth(sc, width, sc->width, cur_fv);
|
||||
@ -382,13 +377,13 @@ void ffw_set_metric(double ascent, double descent)
|
||||
/*
|
||||
* TODO:bitmap, reference have not been considered in this function
|
||||
*/
|
||||
void ffw_set_widths(int * width_list, int mapping_len,
|
||||
void ffw_set_widths(int * width_list, int mapping_len,
|
||||
int stretch_narrow, int squeeze_wide)
|
||||
{
|
||||
SplineFont * sf = cur_fv->sf;
|
||||
|
||||
if(sf->onlybitmaps
|
||||
&& cur_fv->active_bitmap != NULL
|
||||
if(sf->onlybitmaps
|
||||
&& cur_fv->active_bitmap != NULL
|
||||
&& sf->bitmaps != NULL)
|
||||
{
|
||||
printf("TODO: width vs bitmap\n");
|
||||
@ -402,7 +397,7 @@ void ffw_set_widths(int * width_list, int mapping_len,
|
||||
/*
|
||||
* Don't mess with it if the glyphs is not used.
|
||||
*/
|
||||
if(width_list[i] == -1)
|
||||
if(width_list[i] == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -417,9 +412,9 @@ void ffw_set_widths(int * width_list, int mapping_len,
|
||||
}
|
||||
else if(((sc->width > EPS)
|
||||
&& (((sc->width > width_list[i] + EPS) && (squeeze_wide))
|
||||
|| ((sc->width < width_list[i] - EPS) && (stretch_narrow)))))
|
||||
|| ((sc->width < width_list[i] - EPS) && (stretch_narrow)))))
|
||||
{
|
||||
real transform[6];
|
||||
real transform[6];
|
||||
transform[0] = ((double)width_list[i]) / (sc->width);
|
||||
transform[3] = 1.0;
|
||||
transform[1] = transform[2] = transform[4] = transform[5] = 0;
|
||||
@ -448,7 +443,7 @@ void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy,
|
||||
{
|
||||
int a = cur_fv->sf->ascent;
|
||||
int d = cur_fv->sf->descent;
|
||||
real transform[6];
|
||||
real transform[6];
|
||||
transform[0] = 1.0;
|
||||
transform[3] = 1.0;
|
||||
transform[1] = transform[2] = 0.0;
|
||||
|
@ -12,19 +12,17 @@
|
||||
|
||||
#include "path.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
int mkdir(const char *pathname, mode_t mode) {
|
||||
if (::GetFileAttributes(pathname) == FILE_ATTRIBUTE_DIRECTORY) {
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
return ::CreateDirectory(pathname, NULL) ? 0 : -1;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
# include <direct.h>
|
||||
# define STAT _stat
|
||||
# define MKDIR(A, B) mkdir(A)
|
||||
#else
|
||||
# define STAT stat
|
||||
# define MKDIR(A, B) mkdir(A, B)
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
void create_directories(const string & path)
|
||||
@ -36,21 +34,15 @@ void create_directories(const string & path)
|
||||
{
|
||||
create_directories(path.substr(0, idx));
|
||||
}
|
||||
|
||||
int r = mkdir(path.c_str(), S_IRWXU);
|
||||
|
||||
int r = MKDIR(path.c_str(), S_IRWXU);
|
||||
if(r != 0)
|
||||
{
|
||||
if(errno == EEXIST)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
struct _stat32 stat_buf;
|
||||
if((_stat32(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
||||
struct STAT stat_buf;
|
||||
if((STAT(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
||||
return;
|
||||
#else
|
||||
struct stat stat_buf;
|
||||
if((stat(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
throw string("Cannot create directory: ") + path;
|
||||
@ -61,8 +53,8 @@ bool sanitize_filename(string & filename)
|
||||
{
|
||||
string sanitized;
|
||||
bool format_specifier_found = false;
|
||||
|
||||
for(size_t i = 0; i < filename.size(); i++)
|
||||
|
||||
for(size_t i = 0; i < filename.size(); i++)
|
||||
{
|
||||
if('%' == filename[i])
|
||||
{
|
||||
@ -71,7 +63,7 @@ bool sanitize_filename(string & filename)
|
||||
sanitized.push_back('%');
|
||||
sanitized.push_back('%');
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// We haven't found the format specifier yet, so see if we can use this one as a valid formatter
|
||||
size_t original_i = i;
|
||||
@ -80,14 +72,14 @@ bool sanitize_filename(string & filename)
|
||||
while(++i < filename.size())
|
||||
{
|
||||
tmp.push_back(filename[i]);
|
||||
|
||||
|
||||
// If we aren't still in option specifiers, stop looking
|
||||
if(!strchr("0123456789", filename[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check to see if we yielded a valid format specifier
|
||||
if('d' == tmp[tmp.size()-1])
|
||||
{
|
||||
@ -105,7 +97,7 @@ bool sanitize_filename(string & filename)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
sanitized.push_back(filename[i]);
|
||||
}
|
||||
@ -114,7 +106,7 @@ bool sanitize_filename(string & filename)
|
||||
// Only sanitize if it is a valid format.
|
||||
if(format_specifier_found)
|
||||
{
|
||||
filename.assign(sanitized);
|
||||
filename.assign(sanitized);
|
||||
}
|
||||
|
||||
return format_specifier_found;
|
||||
@ -128,7 +120,7 @@ bool is_truetype_suffix(const string & suffix)
|
||||
string get_filename (const string & path)
|
||||
{
|
||||
size_t idx = path.rfind('/');
|
||||
if(idx == string::npos)
|
||||
if(idx == string::npos)
|
||||
return path;
|
||||
else if (idx == path.size() - 1)
|
||||
return "";
|
||||
@ -151,4 +143,4 @@ string get_suffix(const string & path)
|
||||
}
|
||||
|
||||
|
||||
} //namespace pdf2htmlEX
|
||||
} //namespace pdf2htmlEX
|
||||
|
Loading…
Reference in New Issue
Block a user