Re: [poppler] poppler/Array.cc poppler/Dict.cc

2018-07-20 Thread Albert Astals Cid
El dimarts, 8 de maig de 2018, a les 19:26:57 CEST, Adam Reichold va escriure:
> Hello again,
> 
> sorry for the rapid succession of patches.
> 
> The attached version fixes a linker issue due to non-exported weak
> symbols and fixes all users of Dict::add to not call copyString 

The behaviour change in Dict:add is really bad, i know people are not supposed 
to use the internal headers, but they still do, and i've no idea how many leaks 
we would cause if we merge this.

Any idea how to prevent it other than doing a source incompatible change (i.e 
renaming add to insert) so at least their code stops compiling and maybe they 
look at the differences?

Or can we even maybe keep the old behaviour?

Cheers,
  Albert

> and leak
> memory since std::string will take care of this including SBO.
> 
> Best regards, Adam.
> 
> P.S.: Will try to do some performance comparisons against master but
> this will take at least a day due to the limitations of my machine.
> 
> Am 08.05.2018 um 08:23 schrieb Adam Reichold:
> > Also cleaned up the includes a bit...
> > 
> > Am 08.05.2018 um 08:01 schrieb Adam Reichold:
> >> Hello again again,
> >>
> >> Am 08.05.2018 um 07:37 schrieb Adam Reichold:
> >>> Hello again,
> >>>
> >>> Am 08.05.2018 um 00:12 schrieb Albert Astals Cid:
>  El dilluns, 7 de maig de 2018, a les 23:03:00 CEST, Adam Reichold va 
>  escriure:
> > Hello,
> >
> > it is probably already too much purely technical code churn for this
> > release cycle, but the use of memmove got me thinking how an
> > implementation of Dict with more STL usage would look like.
> >
> > The result is attached, requesting comments on whether this is
> > considered useful or not.
> 
>  The remove implementation is wrong since it breaks sorting.
> >>>
> >>> Could you explain in more detail? My thinking was that any sublist of a
> >>> sorted list is also sorted and hence removing an element of a list
> >>> cannot break its sorting? (And since we do not increase the size by
> >>> removing an element, we cannot reach SORT_LENGTH_LOWER_LIMIT if we were
> >>> not there already.)
> >>
> >> Sorry, that took a minute... Because of the swap... But actually, there
> >> already is std::vector::erase which does all the tricks like using
> >> memmove if it is statically safe, so it should actually be simpler.
> >>
> >> Fixed version attached...
> >>
> >>> Best regards,
> >>> Adam
> >>>
>  Cheers,
>    Albert
> 
> >
> > Best regards,
> > Adam
> >
> > Am 07.05.2018 um 19:14 schrieb Albert Astals Cid:
> >>  poppler/Array.cc |2 +-
> >>  poppler/Dict.cc  |2 +-
> >>  2 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >> New commits:
> >> commit 07b8f838b3d8859a3ad34a3140bb24475bd6ac2c
> >> Author: Albert Astals Cid 
> >> Date:   Mon May 7 19:13:07 2018 +0200
> >>
> >> cast to void * to bypass new gcc -Wclass-memaccess warning
> >> 
> >> Yes what we're doing there is a bit nasty but it works :D
> >>
> >> diff --git a/poppler/Array.cc b/poppler/Array.cc
> >> index 3276349f..e8aa34ea 100644
> >> --- a/poppler/Array.cc
> >> +++ b/poppler/Array.cc
> >> @@ -112,7 +112,7 @@ void Array::remove(int i) {
> >>
> >>  #endif
> >>  
> >>}
> >>--length;
> >>
> >> -  memmove( elems + i, elems + i + 1, sizeof(elems[0]) * (length - i) 
> >> );
> >> +  memmove( static_cast(elems + i), elems + i + 1, 
> >> sizeof(elems[0])
> >> * (length - i) );> 
> >>  }
> >>  
> >>  Object Array::get(int i, int recursion) const {
> >>
> >> diff --git a/poppler/Dict.cc b/poppler/Dict.cc
> >> index a431f7eb..bc86fd77 100644
> >> --- a/poppler/Dict.cc
> >> +++ b/poppler/Dict.cc
> >> @@ -201,7 +201,7 @@ void Dict::remove(const char *key) {
> >>
> >>gfree(entries[pos].key);
> >>entries[pos].val.free();
> >>if (pos != length) {
> >>
> >> -memmove([pos], [pos + 1], (length - pos) *
> >> sizeof(DictEntry)); +memmove(static_cast([pos]),
> >> [pos + 1], (length - pos) * sizeof(DictEntry));> 
> >>}
> >>  
> >>  }
> >>
> >>} else {
> >>
> >> ___
> >> poppler mailing list
> >> poppler@lists.freedesktop.org
> >> https://lists.freedesktop.org/mailman/listinfo/poppler
> 
> 
> 
> 
>  ___
>  poppler mailing list
>  poppler@lists.freedesktop.org
>  https://lists.freedesktop.org/mailman/listinfo/poppler
> 
> >>>
> >>>
> >>>
> >>> ___
> >>> poppler mailing list
> >>> poppler@lists.freedesktop.org
> >>> https://lists.freedesktop.org/mailman/listinfo/poppler
> >>>
> >>>
> >>>
> >>> ___
> >>> poppler 

[poppler] cpp/poppler-page.cpp cpp/poppler-page.h cpp/poppler-private.h

2018-07-20 Thread Albert Astals Cid
 cpp/poppler-page.cpp  |7 +++
 cpp/poppler-page.h|6 ++
 cpp/poppler-private.h |2 ++
 3 files changed, 15 insertions(+)

New commits:
commit 6c4eaf5642439d87dafa03391441bb3e7f3a98c4
Author: Zsombor Hollay-Horvath 
Date:   Sat Jul 21 00:28:50 2018 +0200

cpp: Add rotation() to text_box

Bug #106562

diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp
index a4ebfe51..1dfc9c75 100644
--- a/cpp/poppler-page.cpp
+++ b/cpp/poppler-page.cpp
@@ -4,6 +4,7 @@
  * Copyright (C) 2017, Jason Alan Palmer 
  * Copyright (C) 2018, Suzuki Toshiya 
  * Copyright (C) 2018, Adam Reichold 
+ * Copyright (C) 2018, Zsombor Hollay-Horvath 
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -309,6 +310,11 @@ rectf text_box::bbox() const
 return m_data->bbox;
 }
 
+int text_box::rotation() const
+{
+return m_data->rotation;
+}
+
 rectf text_box::char_bbox(size_t i) const
 {
 if (i < m_data->char_bboxes.size())
@@ -363,6 +369,7 @@ std::vector page::text_list() const
 text_box tb{new text_box_data{
 ustr,
 {xMin, yMin, xMax-xMin, yMax-yMin},
+word->getRotation(),
 {},
 word->hasSpaceAfter() == gTrue
 }};
diff --git a/cpp/poppler-page.h b/cpp/poppler-page.h
index 93a13d18..a33192d8 100644
--- a/cpp/poppler-page.h
+++ b/cpp/poppler-page.h
@@ -2,6 +2,7 @@
  * Copyright (C) 2009-2010, Pino Toscano 
  * Copyright (C) 2018, Suzuki Toshiya 
  * Copyright (C) 2018, Albert Astals Cid 
+ * Copyright (C) 2018, Zsombor Hollay-Horvath 
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,6 +44,11 @@ public:
 rectf bbox() const;
 
 /**
+  \since 0.68
+*/
+int   rotation() const;
+
+/**
Get a bbox for the i-th glyph
 
This method returns a rectf of the bounding box for
diff --git a/cpp/poppler-private.h b/cpp/poppler-private.h
index 501c4fc4..71cf65a4 100644
--- a/cpp/poppler-private.h
+++ b/cpp/poppler-private.h
@@ -6,6 +6,7 @@
  * Copyright (C) 2018, Suzuki Toshiya 
  * Copyright (C) 2018, Adam Reichold 
  * Copyright (C) 2018 Albert Astals Cid 
+ * Copyright (C) 2018, Zsombor Hollay-Horvath 
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -76,6 +77,7 @@ struct text_box_data
 
 ustring text;
 rectf bbox;
+int rotation;
 std::vector char_bboxes;
 bool has_space_after;
 };
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


Re: [poppler] utils\HtmlOutputDev.cc -> dumpAsXML - Rounded coordinates

2018-07-20 Thread Albert Astals Cid
Pushed.

Cheers,
  Albert

El dijous, 21 de juny de 2018, a les 15:59:51 CEST, Thibaut Brard va escriure:
> Hello,
> 
> I suggest to name the parameter "-noroundcoord" (insted of
> "-accuratecoordinates")
> with that description: "do not round coordinates (with XML output only)"
> Of course I'm open to any other suggestion
> 
> In attachment the new patch with fixed spacing
> 
> --
> Cordialement / Regards
> Thibaut Brard
> 
> 2018-06-20 0:19 GMT+02:00 Albert Astals Cid :
> 
> > El dilluns, 11 de juny de 2018, a les 17:32:27 CEST, Thibaut Brard va
> > escriure:
> > >  Hello!
> > >
> > > I'm using poppler to convert PDF document into XML file and I'm facing
> > few
> > > problems with rounded coordinates.
> > >
> > > In my opinion, the xoutRound macro should be called only when generating
> > > complex HTML documents, but not inside the dumpAsXML method (option :
> > -xml):
> > > when dealing with XML we wish to keep the floating precision.
> > > (For backward-compatibility, this could be another option when calling
> > > /pdftohtml)
> > >
> > > Do you agree or did I miss anything?
> >
> > The spacing is wrong, though that file spacing is nuts, that function at
> > least
> > seems to be reasonable and using two spaces for each indentation. Please
> > amend
> > the patch to do that.
> >
> > Also i don't think anyone would understand what
> >   "enable accurate coordinates output (for XML post-processing)"
> > actually means. I would like a reword of the sentence, possibly including
> > the
> > word "round", something like "Do not round coordinates" or similar.
> >
> > What do you think?
> >
> > Cheers,
> >   Albert
> >
> >
> > >
> > >
> > > PATCH utils\HtmlOutputDev.cc:
> > >
> > >   763  - fprintf(f,"yMin),
> > > xoutRound(img->xMin));
> > >   764  - fprintf(f,"width=\"%d\" height=\"%d\"
> > ",xoutRound(img->xMax-img->
> > > xMin),xoutRound(img->yMax-img->yMin));
> > >   763  + fprintf(f,"yMin,img->xMin);
> > >   764  + fprintf(f,"width=\"%f\" height=\"%f\"
> > ",img->xMax-img->xMin,img->
> > > yMax-img->yMin);
> > >
> > >
> > >   771  - fprintf(f,"yMin),
> > > xoutRound(tmp->xMin));
> > >   772  - fprintf(f,"width=\"%d\" height=\"%d\"
> > ",xoutRound(tmp->xMax-tmp->
> > > xMin),xoutRound(tmp->yMax-tmp->yMin));
> > >   771  + fprintf(f,"yMin,tmp->xMin);
> > >   772  + fprintf(f,"width=\"%f\" height=\"%f\"
> > ",tmp->xMax-tmp->xMin,tmp->
> > > yMax-tmp->yMin);
> > >
> > >
> > > Regards,
> > > --Thibaut
> >
> >
> >
> >
> >
> 




___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


[poppler] utils/HtmlOutputDev.cc utils/pdftohtml.1 utils/pdftohtml.cc

2018-07-20 Thread Albert Astals Cid
 utils/HtmlOutputDev.cc |   22 ++
 utils/pdftohtml.1  |3 +++
 utils/pdftohtml.cc |4 
 3 files changed, 25 insertions(+), 4 deletions(-)

New commits:
commit bcd89bc0abb2cc05d3dc428074bb24b450ab7cf0
Author: Thibaut Brard 
Date:   Sat Jul 21 00:17:58 2018 +0200

pdftohtml: Add option to not round coordinates

when outputing as xml

diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index ace303b3..8a088c22 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -41,6 +41,7 @@
 // Copyright (C) 2016 Vincent Le Garrec 
 // Copyright (C) 2017 Caolán McNamara 
 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, 
. Work sponsored by the LiMux project of the city of Munich
+// Copyright (C) 2018 Thibaut Brard 
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -109,6 +110,7 @@ extern GBool printHtml;
 extern GBool noframes;
 extern GBool stout;
 extern GBool xml;
+extern GBool noRoundedCoordinates;
 extern GBool showHidden;
 extern GBool noMerge;
 
@@ -760,16 +762,28 @@ void HtmlPage::dumpAsXML(FILE* f,int page){
   int listlen=imgList->getLength();
   for (int i = 0; i < listlen; i++) {
 HtmlImage *img = (HtmlImage*)imgList->del(0);
-fprintf(f,"yMin),xoutRound(img->xMin));
-fprintf(f,"width=\"%d\" height=\"%d\" 
",xoutRound(img->xMax-img->xMin),xoutRound(img->yMax-img->yMin));
+if (!noRoundedCoordinates) {
+  fprintf(f, "yMin), 
xoutRound(img->xMin));
+  fprintf(f, "width=\"%d\" height=\"%d\" ", xoutRound(img->xMax - 
img->xMin), xoutRound(img->yMax - img->yMin));
+}
+else {
+  fprintf(f, "yMin, img->xMin);
+  fprintf(f, "width=\"%f\" height=\"%f\" ", img->xMax - img->xMin, 
img->yMax - img->yMin);
+}
 fprintf(f,"src=\"%s\"/>\n",img->fName->getCString());
 delete img;
   }
 
   for(HtmlString *tmp=yxStrings;tmp;tmp=tmp->yxNext){
 if (tmp->htext){
-  fprintf(f,"yMin),xoutRound(tmp->xMin));
-  fprintf(f,"width=\"%d\" height=\"%d\" 
",xoutRound(tmp->xMax-tmp->xMin),xoutRound(tmp->yMax-tmp->yMin));
+  if (!noRoundedCoordinates) {
+fprintf(f, "yMin), 
xoutRound(tmp->xMin));
+fprintf(f, "width=\"%d\" height=\"%d\" ", xoutRound(tmp->xMax - 
tmp->xMin), xoutRound(tmp->yMax - tmp->yMin));
+  }
+  else {
+fprintf(f, "yMin, tmp->xMin);
+fprintf(f, "width=\"%f\" height=\"%f\" ", tmp->xMax - tmp->xMin, 
tmp->yMax - tmp->yMin);
+  }
   fprintf(f,"font=\"%d\">", tmp->fontpos);
   fputs(tmp->htext->getCString(),f);
   fputs("\n",f);
diff --git a/utils/pdftohtml.1 b/utils/pdftohtml.1
index 5de42880..5d711ba9 100644
--- a/utils/pdftohtml.1
+++ b/utils/pdftohtml.1
@@ -58,6 +58,9 @@ zoom the PDF document (default 1.5)
 .B \-xml
 output for XML post-processing
 .TP
+.B \-noRoundedCoordinates
+do not round coordinates (with XML output only)
+.TP
 .B \-enc 
 output text encoding name
 .TP
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index 04aeb1bc..b82c2552 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -26,6 +26,7 @@
 // Copyright (C) 2015 William Bader 
 // Copyright (C) 2017 Adrian Johnson 
 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, 
. Work sponsored by the LiMux project of the city of Munich
+// Copyright (C) 2018 Thibaut Brard 
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -81,6 +82,7 @@ static double scale=1.5;
 GBool noframes=gFalse;
 GBool stout=gFalse;
 GBool xml=gFalse;
+GBool noRoundedCoordinates = gFalse;
 static GBool errQuiet=gFalse;
 static GBool noDrm=gFalse;
 double wordBreakThreshold=10;  // 10%, below converted into a coefficient - 0.1
@@ -130,6 +132,8 @@ static const ArgDesc argDesc[] = {
"zoom the pdf document (default 1.5)"},
   {"-xml",argFlag,, 0,
"output for XML post-processing"},
+  {"-noroundcoord", argFlag, , 0,
+"do not round coordinates (with XML output only)"},
   {"-hidden", argFlag,   ,   0,
"output hidden text"},
   {"-nomerge", argFlag, , 0,
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


[poppler] goo/JpegWriter.cc

2018-07-20 Thread Albert Astals Cid
 goo/JpegWriter.cc |8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

New commits:
commit 6ef17493c7d5344aba4278017724746e63659f7f
Author: Albert Astals Cid 
Date:   Sat Jul 21 00:14:07 2018 +0200

JpegWriter: Use the C++11 cascading constructors

diff --git a/goo/JpegWriter.cc b/goo/JpegWriter.cc
index ff15fce5..16c97afe 100644
--- a/goo/JpegWriter.cc
+++ b/goo/JpegWriter.cc
@@ -9,7 +9,7 @@
 // Copyright (C) 2010 Harry Roberts 
 // Copyright (C) 2011 Thomas Freitag 
 // Copyright (C) 2013 Peter Breitenlohner 
-// Copyright (C) 2017 Albert Astals Cid 
+// Copyright (C) 2017, 2018 Albert Astals Cid 
 // Copyright (C) 2018 Martin Packman 
 //
 //
@@ -54,12 +54,8 @@ JpegWriter::JpegWriter(int q, bool p, Format formatA)
 }
 
 JpegWriter::JpegWriter(Format formatA)
+ : JpegWriter(-1, false, formatA)
 {
-  priv = new JpegWriterPrivate;
-  priv->progressive = false;
-  priv->optimize = false;
-  priv->quality = -1;
-  priv->format = formatA;
 }
 
 JpegWriter::~JpegWriter()
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


Re: [poppler] [PATCH] Add -jpegopt optimize option support to utils

2018-07-20 Thread Martin (gzlist)
On 20 July 2018 at 22:43, Albert Astals Cid  wrote:
>
> Pushed, I removed the changes to the man pages that were not related to this 
> specific change, we can discuss them in a different thread if you think makes 
> sense (I kind of agree your definition of progressive was probably better, 
> but I didn't want to have "unrelated" changes in the commit)

Thanks! Yes, fair enough, probably better to do a pass over the
manpage wording as a separate change.

Martin
___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


Re: [poppler] [PATCH] Add -jpegopt optimize option support to utils

2018-07-20 Thread Albert Astals Cid
El dimecres, 4 de juliol de 2018, a les 20:07:10 CEST, Martin (gzlist) va 
escriure:
> On 24 June 2018 at 23:12, Martin (gzlist)  wrote:
> >
> > I've changed the print ones in pdftocairo, see amended patch also with
> > other wording tweaks attached.
> 
> Is there anything else I can do to help you review this patch?
> 
> Am happy to do another pass over the documentation as a separate
> change if that would help.

Pushed, I removed the changes to the man pages that were not related to this 
specific change, we can discuss them in a different thread if you think makes 
sense (I kind of agree your definition of progressive was probably better, but 
I didn't want to have "unrelated" changes in the commit)

Cheers,
  Albert

> 
> Martin
> ___
> poppler mailing list
> poppler@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/poppler
> 




___
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler


[poppler] goo/JpegWriter.cc goo/JpegWriter.h splash/SplashBitmap.cc splash/SplashBitmap.h utils/pdftocairo.1 utils/pdftocairo.cc utils/pdftoppm.1 utils/pdftoppm.cc

2018-07-20 Thread Albert Astals Cid
 goo/JpegWriter.cc  |   12 
 goo/JpegWriter.h   |2 ++
 splash/SplashBitmap.cc |2 ++
 splash/SplashBitmap.h  |2 ++
 utils/pdftocairo.1 |6 ++
 utils/pdftocairo.cc|   11 +++
 utils/pdftoppm.1   |6 ++
 utils/pdftoppm.cc  |   11 +++
 8 files changed, 52 insertions(+)

New commits:
commit 0b4ad184b479e24b13b0453b89859b75b699b131
Author: Martin Packman 
Date:   Fri Jul 20 23:34:37 2018 +0200

Add -jpegopt optimize option support to utils

New option 'optimize=y' for utils that take a -jpegopt param,
pdftocairo and pdftoppm. This corresponds to the cjpeg -optimize
flag, and slightly reduces the size of the output jpeg but uses
additional cpu and memory.

New jpegOptimize boolean in splash/SplashBitmap WriteImgParams.

New setOptimize method on goo/JpegWriter taking a boolean.

Update manpages for new option.

diff --git a/goo/JpegWriter.cc b/goo/JpegWriter.cc
index 37c15c2a..ff15fce5 100644
--- a/goo/JpegWriter.cc
+++ b/goo/JpegWriter.cc
@@ -10,6 +10,7 @@
 // Copyright (C) 2011 Thomas Freitag 
 // Copyright (C) 2013 Peter Breitenlohner 
 // Copyright (C) 2017 Albert Astals Cid 
+// Copyright (C) 2018 Martin Packman 
 //
 //
 
@@ -25,6 +26,7 @@ extern "C" {
 
 struct JpegWriterPrivate {
   bool progressive;
+  bool optimize;
   int quality;
   JpegWriter::Format format;
   struct jpeg_compress_struct cinfo;
@@ -46,6 +48,7 @@ JpegWriter::JpegWriter(int q, bool p, Format formatA)
 {
   priv = new JpegWriterPrivate;
   priv->progressive = p;
+  priv->optimize = false;
   priv->quality = q;
   priv->format = formatA;
 }
@@ -54,6 +57,7 @@ JpegWriter::JpegWriter(Format formatA)
 {
   priv = new JpegWriterPrivate;
   priv->progressive = false;
+  priv->optimize = false;
   priv->quality = -1;
   priv->format = formatA;
 }
@@ -75,6 +79,11 @@ void JpegWriter::setProgressive(bool progressive)
   priv->progressive = progressive;
 }
 
+void JpegWriter::setOptimize(bool optimize)
+{
+  priv->optimize = optimize;
+}
+
 bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
 {
   // Setup error handler
@@ -137,6 +146,9 @@ bool JpegWriter::init(FILE *f, int width, int height, int 
hDPI, int vDPI)
 jpeg_simple_progression(>cinfo);
   }
 
+  // Set whether to compute optimal Huffman coding tables
+  priv->cinfo.optimize_coding = priv->optimize;
+
   // Get ready for data
   jpeg_start_compress(>cinfo, TRUE);
 
diff --git a/goo/JpegWriter.h b/goo/JpegWriter.h
index 9a68bcc9..40de0ec2 100644
--- a/goo/JpegWriter.h
+++ b/goo/JpegWriter.h
@@ -11,6 +11,7 @@
 // Copyright (C) 2010 Brian Cameron 
 // Copyright (C) 2011 Albert Astals Cid 
 // Copyright (C) 2011 Thomas Freitag 
+// Copyright (C) 2018 Martin Packman 
 //
 //
 
@@ -41,6 +42,7 @@ public:
 
   void setQuality(int quality);
   void setProgressive(bool progressive);
+  void setOptimize(bool optimize);
   bool init(FILE *f, int width, int height, int hDPI, int vDPI) override;
 
   bool writePointers(unsigned char **rowPointers, int rowCount) override;
diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc
index 2bec9f93..cc4b6155 100644
--- a/splash/SplashBitmap.cc
+++ b/splash/SplashBitmap.cc
@@ -23,6 +23,7 @@
 // Copyright (C) 2012 Anthony Wesley 
 // Copyright (C) 2015 Adam Reichold 
 // Copyright (C) 2016 Kenji Uno 
+// Copyright (C) 2018 Martin Packman 
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -356,6 +357,7 @@ void SplashBitmap::setJpegParams(ImgWriter *writer, 
WriteImgParams* params)
 #ifdef ENABLE_LIBJPEG
   if (params) {
 static_cast(writer)->setProgressive(params->jpegProgressive);
+static_cast(writer)->setOptimize(params->jpegOptimize);
 if (params->jpegQuality >= 0)
   static_cast(writer)->setQuality(params->jpegQuality);
   }
diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h
index 092bd4cf..01c972c3 100644
--- a/splash/SplashBitmap.h
+++ b/splash/SplashBitmap.h
@@ -22,6 +22,7 @@
 // Copyright (C) 2012 Thomas Freitag 
 // Copyright (C) 2015 Adam Reichold 
 // Copyright (C) 2016 Kenji Uno 
+// Copyright (C) 2018 Martin Packman 
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -81,6 +82,7 @@ public:
 int jpegQuality = -1;
 GBool jpegProgressive = gFalse;
 GooString tiffCompression;
+GBool jpegOptimize = gFalse;
   };
 
   SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int 
hDPI, int vDPI, WriteImgParams* params = nullptr);
diff --git a/utils/pdftocairo.1 b/utils/pdftocairo.1
index 3a60b73e..8de23925 100644
--- a/utils/pdftocairo.1
+++ b/utils/pdftocairo.1
@@ -310,6 +310,12 @@ Selects