Skip to content

Commit

Permalink
Improve metadata and font support
Browse files Browse the repository at this point in the history
Added document metadata and PDF document properties support plus font style and weight emulation
  • Loading branch information
gmottram authored and pbrant committed Jul 21, 2012
1 parent ccbaee6 commit c658cfc
Show file tree
Hide file tree
Showing 14 changed files with 879 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ public FontSpecification getFont(CssContext ctx) {
return _font;
}

public FontSpecification getFontSpecification() {
return _font;
}

private IdentValue resolveAbsoluteFontSize() {
FSDerivedValue fontSize = valueByName(CSSName.FONT_SIZE);
if (! (fontSize instanceof IdentValue)) {
Expand Down Expand Up @@ -453,7 +457,7 @@ public float getLineHeight(CssContext ctx) {
// Make sure rasterized characters will (probably) fit inside
// the line box
FSFontMetrics metrics = getFSFontMetrics(ctx);
float lineHeight2 = (float)Math.ceil(metrics.getDescent() + Math.round(metrics.getAscent()));
float lineHeight2 = (float)Math.ceil(metrics.getDescent() + metrics.getAscent());
_lineHeight = Math.max(lineHeight1, lineHeight2);
} else if (isLength(CSSName.LINE_HEIGHT)) {
//could be more elegant, I suppose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.xhtmlrenderer.css.style.CssContext;
import org.xhtmlrenderer.css.style.derived.BorderPropertySet;
import org.xhtmlrenderer.css.style.derived.LengthValue;
import org.xhtmlrenderer.css.value.FontSpecification;
import org.xhtmlrenderer.extend.FSImage;
import org.xhtmlrenderer.extend.OutputDevice;
import org.xhtmlrenderer.util.Configuration;
Expand All @@ -46,15 +47,19 @@
* implementations for many <code>OutputDevice</code> methods.
*/
public abstract class AbstractOutputDevice implements OutputDevice {
protected abstract void drawLine(int x1, int y1, int x2, int y2);

private FontSpecification _fontSpec;

protected abstract void drawLine(int x1, int y1, int x2, int y2);

public void drawText(RenderingContext c, InlineText inlineText) {
InlineLayoutBox iB = inlineText.getParent();
String text = inlineText.getSubstring();

if (text != null && text.length() > 0) {
setColor(iB.getStyle().getColor());
setFont(iB.getStyle().getFSFont(c));
setFontSpecification(iB.getStyle().getFontSpecification());
if (inlineText.getParent().getStyle().isTextJustify()) {
JustificationInfo info = inlineText.getParent().getLineBox().getJustificationInfo();
if (info != null) {
Expand Down Expand Up @@ -395,4 +400,22 @@ private int calcBackgroundSizeLength(CssContext c, CalculatedStyle style, Proper
c);
}
}

/**
* Gets the FontSpecification for this AbstractOutputDevice.
*
* @return current FontSpecification.
*/
public FontSpecification getFontSpecification() {
return _fontSpec;
}

/**
* Sets the FontSpecification for this AbstractOutputDevice.
*
* @param fs current FontSpecification.
*/
public void setFontSpecification(FontSpecification fs) {
_fontSpec = fs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public static List getChildren(Element parent, String name) {
* @return a String with the text content of an element (may be an empty string but will not be null).
*/
public static String getText(Element parent) {
StringBuilder sb = new StringBuilder();
getText(parent, sb);
StringBuilder sb = new StringBuilder();
getText(parent, sb);
return sb.toString();
}

Expand All @@ -79,10 +79,10 @@ public static void getText(Element parent, StringBuilder sb) {
for (int i = 0; i < children.getLength(); i++) {
Node n = (Node)children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
getText((Element)n, sb);
getText((Element)n, sb);
} else if (n.getNodeType() == Node.TEXT_NODE) {
sb.append(n.getNodeValue());
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class DefaultPDFCreationListener implements PDFCreationListener {
*/
public void preOpen(ITextRenderer iTextRenderer) { }

/**
* {@inheritDoc}
*/
public void preWrite(ITextRenderer iTextRenderer, int pageCount) {}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import org.xhtmlrenderer.util.XRLog;
import org.xhtmlrenderer.util.XRRuntimeException;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.BaseFont;
import java.io.*;
import java.util.*;

Expand Down Expand Up @@ -397,7 +395,7 @@ private FSFont resolveFont(SharedContext ctx, String fontFamily, float size, Ide
return null;
}

private int convertWeightToInt(IdentValue weight) {
public static int convertWeightToInt(IdentValue weight) {
if (weight == IdentValue.NORMAL) {
return 400;
} else if (weight == IdentValue.BOLD) {
Expand Down
Loading

0 comments on commit c658cfc

Please sign in to comment.