protected void renderRegionViewport(RegionViewport port) {
if (port != null) {
Rectangle2D view = port.getViewArea();
- currentBPPosition = (int) (view.getY() / 1000);
- currentIPPosition = (int) (view.getX() / 1000);
+ // The CTM will transform coordinates relative to
+ // this region-reference area into page coords, so
+ // set origin for the region to 0,0.
+ currentBPPosition = 0; // (int) (view.getY() / 1000);
+ currentIPPosition = 0; // (int) (view.getX() / 1000);
currentBlockIPPosition = currentIPPosition;
RegionReference region = port.getRegion();
+ startVParea(region.getCTM());
if (region.getRegionClass() == Region.BODY) {
renderBodyRegion((BodyRegion) region);
} else {
renderRegion(region);
}
+ endVParea();
}
}
+ protected void startVParea(CTM ctm) { }
+
+ protected void endVParea() { }
+
protected void renderRegion(RegionReference region) {
List blocks = region.getBlocks();
pageReferences.put(page, currentPage.referencePDF());
}
currentStream = this.pdfDoc.makeStream();
- currentStream.add("BT\n");
+ // Transform origin at top left to origin at bottom left
+ currentStream.add("1 0 0 -1 0 " +
+ (int) Math.round(pageHeight / 1000) + " cm\n");
+ //currentStream.add("BT\n");
Page p = page.getPage();
renderPageAreas(p);
- currentStream.add("ET\n");
+ //currentStream.add("ET\n");
currentPage.setContents(currentStream);
this.pdfDoc.addPage(currentPage);
this.pdfDoc.output(ostream);
}
+
+ protected void startVParea(CTM ctm) {
+ // Set the given CTM in the graphics state
+ currentStream.add("q\n");
+ // multiply with current CTM
+ currentStream.add(ctm.toPDFctm() + " cm\n");
+ // Set clip?
+ }
+
+ protected void endVParea() {
+ currentStream.add("Q\n");
+ }
+
+ protected void renderRegion(RegionReference region) {
+ // Draw a rectangle so we can see it!
+ // x=0,y=0,w=ipd,h=bpd
+ currentStream.add("BT\n");
+ super.renderRegion(region);
+ currentStream.add("ET\n");
+ }
+
+
+ protected void renderLineArea(LineArea line) {
+ super.renderLineArea(line);
+ closeText();
+ }
+
public void renderCharacter(Character ch) {
super.renderCharacter(ch);
updateColor(true, pdf);
int rx = currentBlockIPPosition;
- int bl = pageHeight - currentBPPosition;
+ // int bl = pageHeight - currentBPPosition;
+ int bl = currentBPPosition;
// Set letterSpacing
//float ls = fs.getLetterSpacing() / this.currentFontSize;
if (!textOpen || bl != prevWordY) {
closeText();
- pdf.append("1 0 0 1 " + (rx / 1000f) + " " + (bl / 1000f)
+ pdf.append("1 0 0 -1 " + (rx / 1000f) + " " + (bl / 1000f)
+ " Tm [" + startText);
prevWordY = bl;
textOpen = true;