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

Fix issue #3: enable text justification using CSS's text-align #33

Merged
merged 1 commit into from
Aug 28, 2016
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
import com.openhtmltopdf.util.Configuration;
import com.openhtmltopdf.util.XRLog;

import static com.openhtmltopdf.test.DocumentDiffTest.width;

public class PdfBoxOutputDevice extends AbstractOutputDevice implements OutputDevice {
private static final int FILL = 1;
private static final int STROKE = 2;
Expand Down Expand Up @@ -452,10 +454,14 @@ public void drawStringFast(String s, float x, float y, JustificationInfo info, F
_cp.beginText();
_cp.setFont(desc.getFont(), fontSize);
_cp.setTextMatrix((float) mx[0], b, c, (float) mx[3], (float) mx[4], (float) mx[5]);

if (info != null) {
_cp.setTextSpacing(info.getNonSpaceAdjust());
_cp.setSpaceSpacing(info.getSpaceAdjust());

if (info != null ) {
// The JustificationInfo numbers need to be normalized using the current document DPI
_cp.setTextSpacing(info.getNonSpaceAdjust() / _dotsPerPoint);
_cp.setSpaceSpacing(info.getSpaceAdjust() / _dotsPerPoint);
} else {
_cp.setTextSpacing(0.0f);
_cp.setSpaceSpacing(0.0f);
}

_cp.drawString(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,19 @@ public void setMiterLimit(float miterLimit) {
}

public void setTextSpacing(float nonSpaceAdjust) {
// TODO Not currently supported in PDF-BOX.
try {
cs.appendRawCommands(String.format("%f Tc\n", nonSpaceAdjust).replace(',', '.'));
} catch (IOException e) {
logAndThrow("setSpaceSpacing", e);
}
}

public void setSpaceSpacing(float spaceAdjust) {
// TODO Not currently supported in PDF-BOX.
try {
cs.appendRawCommands(String.format("%f Tw\n", spaceAdjust).replace(',', '.'));
} catch (IOException e) {
logAndThrow("setSpaceSpacing", e);
}
}

public void setPdfMatrix(AffineTransform transform) {
Expand Down