[PATCH] Makefile: Reduce file size of figure generated from ibmqx2-labeled.svg

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From 9d3172e3960cb97b301e37ee86913ca391b7cfb3 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@xxxxxxxxx>
Date: Wed, 4 Apr 2018 07:30:45 +0900
Subject: [PATCH] Makefile: Reduce file size of figure generated from ibmqx2-labeled.svg

The .svg file contains a high-resolution scanned bitmap image and
results in a large .pdf file of more than 6.3MB. It is about 46
percent of the size of final perfbook.pdf.

By adding a recipe to convert such .svg files to lower resolution
.png files, perfbook.pdf can be made much smaller.

Size of perfbook.pdf (can vary depending on LaTeX / other tool config):
    before: 13.7 MB
    after:   7.7 MB

DPI=200 is chosen for .png file output. Resulting Figure 17.16 looks
good enough. That said, we should restrict the use of .png in
exceptional cases. Otherwise, we would lose the merit of vector
graphics.

While we are here, remove the comment in target "neatfreak".
There have been make rules to take care of generating necessary
PDF files for quite some time.

NOTE: You need to remove future/ibmqx2-labeled.pdf before doing
"make" to see the effect of this change. Alternatively,
"make clean" removes both .png and .pdf files generated by the
added recipe along with several other files.
The high resolution figure can be restored by overriding the
definition of SVG_LARGE_BITMAP by a make option such as:
"make clean; make SVG_LARGE_BITMAP=".

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
 .gitignore |  1 +
 Makefile   | 19 +++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 3f2e4a9..f0b8339 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
 *.dvi
 *.log
 *.pdf
+*.png
 *.qqz
 *.toc
 *.sav
diff --git a/Makefile b/Makefile
index 873be64..4167e20 100644
--- a/Makefile
+++ b/Makefile
@@ -48,8 +48,10 @@ PDFTARGETS_OF_EPSOTHER := $(filter-out $(PDFTARGETS_OF_EPSORIG),$(PDFTARGETS_OF_
 BIBSOURCES := bib/*.bib alphapf.bst
 
 SVGSOURCES := $(wildcard */*.svg)
-
-PDFTARGETS_OF_SVG := $(SVGSOURCES:%.svg=%.pdf)
+SVG_LARGE_BITMAP := future/ibmqx2-labeled.svg
+PDFTARGETS_OF_SVG := $(filter-out $(SVG_LARGE_BITMAP:%.svg=%.pdf),$(SVGSOURCES:%.svg=%.pdf))
+PNGTARGETS_OF_SVG := $(SVG_LARGE_BITMAP:%.svg=%.png)
+TARGETS_OF_SVG :=  $(PDFTARGETS_OF_SVG) $(PNGTARGETS_OF_SVG)
 
 DOT := $(shell which dot 2>/dev/null)
 
@@ -102,7 +104,7 @@ $(PDFTARGETS:.pdf=.aux): $(LATEXGENERATED) $(LATEXSOURCES)
 autodate.tex: $(LATEXSOURCES) $(BIBSOURCES) $(SVGSOURCES) $(FIGSOURCES) $(DOTSOURCES)
 	sh utilities/autodate.sh >autodate.tex
 
-perfbook_flat.tex: perfbook.tex $(LATEXSOURCES) $(PDFTARGETS_OF_EPS) $(PDFTARGETS_OF_SVG)
+perfbook_flat.tex: perfbook.tex $(LATEXSOURCES) $(PDFTARGETS_OF_EPS) $(TARGETS_OF_SVG)
 	echo > qqz.tex
 	echo > contrib.tex
 	echo > origpub.tex
@@ -206,6 +208,15 @@ endif
 	@inkscape --export-pdf=$@ $<i > /dev/null 2>&1
 	@rm -f $<i
 
+$(PNGTARGETS_OF_SVG): %.png: %.svg
+	@echo "$< --> $@"
+ifndef INKSCAPE
+	$(error "$< --> $@: inkscape not found. Please install it.")
+endif
+	@sh $(FIXSVGFONTS) < $< > $<i
+	@inkscape --export-dpi=200 --export-png=$@ $<i > /dev/null 2>&1
+	@rm -f $<i
+
 help:
 	@echo "Official targets (Latin Modern Typewriter for monospace font):"
 	@echo "  Full,              Abbr."
@@ -238,6 +249,7 @@ clean:
 		-o -name '*.qqz' -o -name '*.toc' -o -name '*.bbl' | xargs rm -f
 	rm -f perfbook_flat.tex perfbook*.out perfbook-*.tex
 	rm -f $(LATEXGENERATED)
+	rm -f $(SVG_LARGE_BITMAP:%.svg=%.pdf) $(PNGTARGETS_OF_SVG)
 	rm -f extraction
 
 distclean: clean
@@ -251,7 +263,6 @@ ls-unused:
 	find . -name .unused | xargs ls
 
 neatfreak: distclean
-	# Don't forget to regenerate the .pdf from each .svg file
 	find . -name '*.pdf' | xargs rm -f
 
 .SECONDEXPANSION:
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux