Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue - rendering of bold fonts #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion src/main/java/net/sf/mcf2pdf/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static void main(String[] args) {
options.addOption("r", true, "Sets the resolution to use for page rendering, in DPI. Default is 150.");
options.addOption("n", true, "Sets the page number to render up to. Default renders all pages.");
options.addOption("b", false, "Prevents rendering of binding between double pages.");
options.addOption("s", true, "Set scaling for fonts which don't support bold text nativly. Default is 0.82.");
options.addOption("x", false, "Generates only XSL-FO content instead of PDF content.");
options.addOption("q", false, "Quiet mode - only errors are logged.");
options.addOption("d", false, "Enables debugging logging output.");
Expand Down Expand Up @@ -148,6 +149,15 @@ public static void main(String[] args) {
if (cl.hasOption("b")) {
binding = false;
}

double sx = 0.82d;
if (cl.hasOption("s")) {
try {
sx = Double.valueOf(cl.getOptionValue("s")).doubleValue();
} catch (Exception e) {
printUsage(options, new ParseException("Parameter for option -s must be a double value."));
}
}

OutputStream finalOut;
if (cl.getArgs()[1].equals("-"))
Expand Down Expand Up @@ -186,7 +196,7 @@ public static void main(String[] args) {

try {
new Mcf2FoConverter(installDir, tempDir, tempImages).convert(
mcfFile, xslFoOut, dpi, binding, maxPageNo);
mcfFile, xslFoOut, dpi, binding, maxPageNo, sx);
xslFoOut.flush();

if (!cl.hasOption("x")) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/mcf2pdf/Mcf2FoConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Mcf2FoConverter(File mcfInstallDir, File mcfTempDir, File tempImageDir) t
* @throws SAXException If any XML related problem occurs, e.g. the input file
* has an invalid format.
*/
public void convert(File mcfFile, OutputStream xslFoOut, int dpi, boolean binding, int maxPageNo) throws IOException, SAXException {
public void convert(File mcfFile, OutputStream xslFoOut, int dpi, boolean binding, int maxPageNo, double sx) throws IOException, SAXException {
// build MCF DOM
log.debug("Reading MCF file");
McfFotobook book = new FotobookBuilder().readFotobook(mcfFile);
Expand All @@ -170,7 +170,7 @@ public void convert(File mcfFile, OutputStream xslFoOut, int dpi, boolean bindin
throw new IOException("No album type definition found for used print product '" + book.getProductName() + "'");

// prepare page render context
context = new PageRenderContext(dpi, resources, albumType);
context = new PageRenderContext(dpi, sx, resources, albumType);

// create XSL-FO document
XslFoDocumentBuilder docBuilder = new XslFoDocumentBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.font.TextAttribute;
import java.awt.geom.AffineTransform;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.Collections;
Expand Down Expand Up @@ -85,7 +86,13 @@ public AttributedCharacterIterator getCharacterIterator(PageRenderContext contex
float fontSizeInch = text.getFontSize() / 72.0f;

map.put(TextAttribute.SIZE, fontSizeInch * context.getTargetDpi());
Font fontOriginal = font;
font = font.deriveFont(map);
if (map.get(TextAttribute.WEIGHT) == TextAttribute.WEIGHT_BOLD && font.getFontName().equals(fontOriginal.getFontName())) {
AffineTransform afT = new AffineTransform();
afT.setToScale(context.getSX(), 1);
font = font.deriveFont(afT);
}
map.put(TextAttribute.FONT, font);

if (text.getText().length() > 0) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/net/sf/mcf2pdf/pagebuild/PageRenderContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@
public final class PageRenderContext {

private final static Log log = LogFactory.getLog(PageRenderContext.class);

private double sx;

private int targetDpi;

private McfResourceScanner resources;

private McfAlbumType albumType;

public PageRenderContext(int targetDpi, McfResourceScanner resources,
public PageRenderContext(int targetDpi, double sx, McfResourceScanner resources,
McfAlbumType albumType) {
this.targetDpi = targetDpi;
this.sx = sx;
this.resources = resources;
this.albumType = albumType;
}
Expand All @@ -49,6 +52,15 @@ public PageRenderContext(int targetDpi, McfResourceScanner resources,
public Log getLog() {
return log;
}

/**
* Returns the scaling factor for fonts that don't natively support bold text.
*
* @return the scaling factor for fonts that don't natively support bold text.
*/
public double getSX() {
return sx;
}

/**
* Returns the target DPI setting.
Expand Down