New feature --fit-every #57

Closed
wants to merge 2 commits into
from
@@ -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;
@@ -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,
@@ -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
{
@@ -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)){
coolwanglu
coolwanglu Dec 13, 2012 Owner

why check param->zoom here

Simanas
Simanas Dec 13, 2012

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

coolwanglu
coolwanglu Dec 13, 2012 Owner

why is that, it would be confusing.

Simanas
Simanas Dec 13, 2012

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.

coolwanglu
coolwanglu Dec 13, 2012 Owner

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.

Simanas
Simanas Dec 13, 2012

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. :)

Simanas
Simanas Dec 13, 2012

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

coolwanglu
coolwanglu Dec 13, 2012 Owner

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/coolwanglu/pdf2htmlEX/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
View
@@ -27,6 +27,7 @@ struct Param
double zoom;
double fit_width, fit_height;
+ int fit_every;
double h_dpi, v_dpi;
int use_cropbox;
View
@@ -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")
View
@@ -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()
@@ -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
View
@@ -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);
@@ -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;