Skip to content

Commit

Permalink
Add the character and word spacing operators and fix the spacing numb…
Browse files Browse the repository at this point in the history
…ers using the document's DPI (#33)
  • Loading branch information
joaomdevel authored and danfickle committed Aug 28, 2016
1 parent 4317965 commit fe1c445
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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

0 comments on commit fe1c445

Please # to comment.