Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

New feature --fit-every #57

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/HTMLRenderer/HTMLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ class HTMLRenderer : public OutputDev
* factor1 & factor 2 are determined according to zoom and font-size-multiplier
*
*/
double text_zoom_factor (void) const { return text_scale_factor1 * text_scale_factor2; }
void determine_scale_factors(int width, int height);
double text_zoom_factor (int page_number);
double text_scale_factor1;
double text_scale_factor2;

Expand Down
78 changes: 45 additions & 33 deletions src/HTMLRenderer/general.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void HTMLRenderer::process(PDFDoc *doc)
}

doc->displayPage(this, i,
text_zoom_factor() * DEFAULT_DPI, text_zoom_factor() * DEFAULT_DPI,
text_zoom_factor(i) * DEFAULT_DPI, text_zoom_factor(i) * DEFAULT_DPI,
0,
(param->use_cropbox == 0),
false, false,
Expand Down Expand Up @@ -235,38 +235,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
/*
* determine scale factors
*/
{
double zoom = 1.0;

vector<double> zoom_factors;

if(is_positive(param->zoom))
{
zoom_factors.push_back(param->zoom);
}

if(is_positive(param->fit_width))
{
zoom_factors.push_back((param->fit_width) / preprocessor.get_max_width());
}

if(is_positive(param->fit_height))
{
zoom_factors.push_back((param->fit_height) / preprocessor.get_max_height());
}

if(zoom_factors.empty())
{
zoom = 1.0;
}
else
{
zoom = *min_element(zoom_factors.begin(), zoom_factors.end());
}

text_scale_factor1 = max<double>(zoom, param->font_size_multiplier);
text_scale_factor2 = zoom / text_scale_factor1;
}
determine_scale_factors(preprocessor.get_max_width(),preprocessor.get_max_height());

// we may output utf8 characters, so always use binary
{
Expand Down Expand Up @@ -393,6 +362,49 @@ void HTMLRenderer::post_process()
}
}

void HTMLRenderer::determine_scale_factors(int width, int height)
{
double zoom = 1.0;

vector<double> zoom_factors;

if(is_positive(param->zoom))
{
zoom_factors.push_back(param->zoom);
}

if(is_positive(param->fit_width))
{
zoom_factors.push_back((param->fit_width) / width);
}

if(is_positive(param->fit_height))
{
zoom_factors.push_back((param->fit_height) / height);
}

if(zoom_factors.empty())
{
zoom = 1.0;
}
else
{
zoom = *min_element(zoom_factors.begin(), zoom_factors.end());
}

text_scale_factor1 = max<double>(zoom, param->font_size_multiplier);
text_scale_factor2 = zoom / text_scale_factor1;
}

double HTMLRenderer::text_zoom_factor (int page_number){

if(is_positive(param->fit_every) && !is_positive(param->zoom)){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why check param->zoom here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed earlier, if zoom is presented, fit_every should not affect anything.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that, it would be confusing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not check it here, then if --zoom, --fit-width, --fit-every is presented it would create unwanted results, because in document with different page sizes this method *min_element(zoom_factors.begin(), zoom_factors.end()) on some pages will return zoom value on some calculated zoom value from --fit-width value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, if more than one of --zoom, --fit-width/height is specified, the "smallest one" will be used.
"--zoom disables --fit-every" is not intuitive to me, and not even written in the manpage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are wrong. Currently the smallest of --zoom, --fit-width/document_width and --fit-height/document_width is used to get text_scale_factors for every page.

In my modification if you remove param->zoom check, then for every page the smallest of --zoom, --fit-width/page_width and --fit-height/page_width will be used, which would be a stupid behavior. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... man page should be modificated if you decide to accept this change.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant --zoom and --fit-width/page_width for each page.

On Thu, Dec 13, 2012 at 8:17 PM, Simanas notifications@github.com wrote:

In src/HTMLRenderer/general.cc:

  • if(zoom_factors.empty())
  • {
  •    zoom = 1.0;
    
  • }
  • else
  • {
  •    zoom = *min_element(zoom_factors.begin(), zoom_factors.end());
    
  • }
  • text_scale_factor1 = max(zoom, param->font_size_multiplier);
  • text_scale_factor2 = zoom / text_scale_factor1;
    +}

+double HTMLRenderer::text_zoom_factor (int page_number){
+

  • if(is_positive(param->fit_every) && !is_positive(param->zoom)){

You are wrong. Currently the smallest of --zoom,
--fit-width/document_width and --fit-height/document_width is used to get
text_scale_factors for every page.

In my modification if you remove param->zoom check, then for every page
the smallest of --zoom, --fit-width/page_width and --fit-height/page_width
will be used, which would be a stupid behavior. :)


Reply to this email directly or view it on GitHubhttps://github.com//pull/57/files#r2406508.

determine_scale_factors(preprocessor.get_page_width(page_number),preprocessor.get_page_height(page_number));
}
return text_scale_factor1 * text_scale_factor2;
}


void HTMLRenderer::set_stream_flags(std::ostream & out)
{
// we output all ID's in hex
Expand Down
1 change: 1 addition & 0 deletions src/Param.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct Param

double zoom;
double fit_width, fit_height;
int fit_every;
double h_dpi, v_dpi;
int use_cropbox;

Expand Down
1 change: 1 addition & 0 deletions src/pdf2htmlEX.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void parse_options (int argc, char **argv)
.add("zoom", &param.zoom, 0, "zoom ratio", nullptr, true)
.add("fit-width", &param.fit_width, 0, "fit width", nullptr, true)
.add("fit-height", &param.fit_height, 0, "fit height", nullptr, true)
.add("fit-every", &param.fit_every, 0, "fit every page to fit-width/height", nullptr, true)
.add("hdpi", &param.h_dpi, 144.0, "horizontal DPI for non-text")
.add("vdpi", &param.v_dpi, 144.0, "vertical DPI for non-text")
.add("use-cropbox", &param.use_cropbox, 0, "use CropBox instead of MediaBox")
Expand Down
5 changes: 4 additions & 1 deletion src/util/Preprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using std::cerr;
using std::endl;
using std::flush;
using std::max;
using std::vector;

Preprocessor::Preprocessor(const Param * param)
: OutputDev()
Expand Down Expand Up @@ -87,7 +88,9 @@ void Preprocessor::drawChar(GfxState *state, double x, double y,
void Preprocessor::startPage(int pageNum, GfxState *state)
{
max_width = max<double>(max_width, state->getPageWidth());
max_height = max<double>(max_height, state->getPageHeight());
max_height = max<double>(max_height, state->getPageHeight());
page_widths[pageNum] = state->getPageWidth();
page_heights[pageNum] = state->getPageHeight();
}

const char * Preprocessor::get_code_map (long long font_id) const
Expand Down
6 changes: 6 additions & 0 deletions src/util/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
#include <PDFDoc.h>
#include <Annot.h>
#include "Param.h"
#include <map>

namespace pdf2htmlEX {

using std::map;

class Preprocessor : public OutputDev {
public:
Preprocessor(const Param * param);
Expand All @@ -45,11 +48,14 @@ class Preprocessor : public OutputDev {
const char * get_code_map (long long font_id) const;
double get_max_width (void) const { return max_width; }
double get_max_height (void) const { return max_height; }
double get_page_width (int page_number) { return page_widths[page_number-1]; }
double get_page_height (int page_number) { return page_heights[page_number-1]; }

protected:
const Param * param;

double max_width, max_height;
map<int,int> page_widths, page_heights;

long long cur_font_id;
char * cur_code_map;
Expand Down