Skip to content

Commit

Permalink
Merge pull request #315 from metanorma/main
Browse files Browse the repository at this point in the history
Import changes from main branch
  • Loading branch information
Intelligent2013 authored Dec 24, 2024
2 parents fb57453 + 17fe733 commit bc7f88e
Show file tree
Hide file tree
Showing 6 changed files with 1,744 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL ?= /bin/bash
endif

#JAR_VERSION := $(shell mvn -q -Dexec.executable="echo" -Dexec.args='$${project.version}' --non-recursive exec:exec -DforceStdout)
JAR_VERSION := 2.10
JAR_VERSION := 2.11
JAR_FILE := mn2pdf-$(JAR_VERSION).jar

all: target/$(JAR_FILE)
Expand Down
10 changes: 5 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ You will need the Java Development Kit (JDK) version 8, Update 241 (8u241) or hi

[source,sh]
----
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.10.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.11.jar --xml-file <XML-FileName> --xsl-file <XSLT-FileName> --pdf-file <Output-PDF-FileName> [--syntax-highlight]
----

e.g.

[source,sh]
----
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.10.jar --xml-file tests/G.191.xml --xsl-file tests/itu.recommendation.xsl --pdf-file tests/G.191.pdf
java -Xss5m -Xmx2048m -jar target/mn2pdf-2.11.jar --xml-file tests/G.191.xml --xsl-file tests/itu.recommendation.xsl --pdf-file tests/G.191.pdf
----

=== PDF encryption features
Expand Down Expand Up @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>2.10</version>
<version>2.11</version>
<name>Metanorma XML to PDF converter</name>
----

Expand All @@ -111,8 +111,8 @@ Tag the same version in Git:

[source,xml]
----
git tag v2.10
git push origin v2.10
git tag v2.11
git push origin v2.11
----

Then the corresponding GitHub release will be automatically created at:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ protected LayoutContext makeChildLayoutContext(LayoutContext context) {
childLC.setStackLimitBP(
context.getStackLimitBP().minus(MinOptMax.getInstance(relDims.bpd)));
childLC.setRefIPD(relDims.ipd);
childLC.setWritingMode(getBlockContainerFO().getWritingMode());
//childLC.setWritingMode(getBlockContainerFO().getWritingMode());
childLC.setWritingMode(context.getWritingMode());
return childLC;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* $Id$ */

package org.apache.fop.layoutmgr.table;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.fop.fo.Constants;
import org.apache.fop.fo.flow.table.EffRow;
import org.apache.fop.fo.flow.table.GridUnit;
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
import org.apache.fop.fo.flow.table.TableColumn;
import org.apache.fop.fo.flow.table.TableRow;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.LengthRangeProperty;
import org.apache.fop.layoutmgr.ElementListObserver;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.util.BreakUtil;

class RowGroupLayoutManager {

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

private static final MinOptMax MAX_STRETCH = MinOptMax.getInstance(0, 0, Integer.MAX_VALUE);

private EffRow[] rowGroup;

private TableLayoutManager tableLM;

private TableStepper tableStepper;

RowGroupLayoutManager(TableLayoutManager tableLM, EffRow[] rowGroup,
TableStepper tableStepper) {
this.tableLM = tableLM;
this.rowGroup = rowGroup;
this.tableStepper = tableStepper;
}

public LinkedList getNextKnuthElements(LayoutContext context, int alignment, int bodyType) {
LinkedList returnList = new LinkedList();
createElementsForRowGroup(context, alignment, bodyType, returnList);

context.updateKeepWithPreviousPending(rowGroup[0].getKeepWithPrevious());
context.updateKeepWithNextPending(rowGroup[rowGroup.length - 1].getKeepWithNext());

int breakBefore = Constants.EN_AUTO;
TableRow firstRow = rowGroup[0].getTableRow();
if (firstRow != null) {
breakBefore = firstRow.getBreakBefore();
}
context.setBreakBefore(BreakUtil.compareBreakClasses(breakBefore,
rowGroup[0].getBreakBefore()));

int breakAfter = Constants.EN_AUTO;
TableRow lastRow = rowGroup[rowGroup.length - 1].getTableRow();
if (lastRow != null) {
breakAfter = lastRow.getBreakAfter();
}
context.setBreakAfter(BreakUtil.compareBreakClasses(breakAfter,
rowGroup[rowGroup.length - 1].getBreakAfter()));

return returnList;
}

/**
* Creates Knuth elements for a row group (see TableRowIterator.getNextRowGroup()).
* @param context Active LayoutContext
* @param alignment alignment indicator
* @param bodyType Indicates what kind of body is being processed (BODY, HEADER or FOOTER)
* @param returnList List to received the generated elements
*/
private void createElementsForRowGroup(LayoutContext context, int alignment,
int bodyType, LinkedList returnList) {
log.debug("Handling row group with " + rowGroup.length + " rows...");
EffRow row;
for (EffRow aRowGroup : rowGroup) {
row = aRowGroup;
for (Object o : row.getGridUnits()) {
GridUnit gu = (GridUnit) o;
if (gu.isPrimary()) {
PrimaryGridUnit primary = gu.getPrimary();
// TODO a new LM must be created for every new static-content
primary.createCellLM();
primary.getCellLM().setParent(tableLM);
//Calculate width of cell
int spanWidth = 0;
Iterator colIter = tableLM.getTable().getColumns().listIterator(
primary.getColIndex());
for (int i = 0, c = primary.getCell().getNumberColumnsSpanned(); i < c; i++) {
spanWidth += ((TableColumn) colIter.next()).getColumnWidth().getValue(
tableLM);
}
LayoutContext childLC = LayoutContext.newInstance();
childLC.setStackLimitBP(context.getStackLimitBP()); //necessary?
childLC.setRefIPD(spanWidth);
childLC.setWritingMode(context.getWritingMode());

//Get the element list for the cell contents
List elems = primary.getCellLM().getNextKnuthElements(
childLC, alignment);
ElementListObserver.observe(elems, "table-cell", primary.getCell().getId());
primary.setElements(elems);
}
}
}
computeRowHeights();
List elements = tableStepper.getCombinedKnuthElementsForRowGroup(context,
rowGroup, bodyType);
returnList.addAll(elements);
}

/**
* Calculate the heights of the rows in the row group, see CSS21, 17.5.3 Table height
* algorithms.
*
* TODO this method will need to be adapted once clarification has been made by the
* W3C regarding whether borders or border-separation must be included or not
*/
private void computeRowHeights() {
log.debug("rowGroup:");
MinOptMax[] rowHeights = new MinOptMax[rowGroup.length];
EffRow row;
for (int rgi = 0; rgi < rowGroup.length; rgi++) {
row = rowGroup[rgi];
// The BPD of the biggest cell in the row
// int maxCellBPD = 0;
MinOptMax explicitRowHeight;
TableRow tableRowFO = rowGroup[rgi].getTableRow();
if (tableRowFO == null) {
rowHeights[rgi] = MAX_STRETCH;
explicitRowHeight = MAX_STRETCH;
} else {
LengthRangeProperty rowBPD = tableRowFO.getBlockProgressionDimension();
rowHeights[rgi] = rowBPD.toMinOptMax(tableLM);
explicitRowHeight = rowBPD.toMinOptMax(tableLM);
}
for (Object o : row.getGridUnits()) {
GridUnit gu = (GridUnit) o;
if (!gu.isEmpty() && gu.getColSpanIndex() == 0 && gu.isLastGridUnitRowSpan()) {
PrimaryGridUnit primary = gu.getPrimary();
int effectiveCellBPD = 0;
LengthRangeProperty cellBPD = primary.getCell().getBlockProgressionDimension();
if (!cellBPD.getMinimum(tableLM).isAuto()) {
effectiveCellBPD = cellBPD.getMinimum(tableLM).getLength()
.getValue(tableLM);
}
if (!cellBPD.getOptimum(tableLM).isAuto()) {
effectiveCellBPD = cellBPD.getOptimum(tableLM).getLength()
.getValue(tableLM);
}
if (gu.getRowSpanIndex() == 0) {
effectiveCellBPD = Math.max(effectiveCellBPD, explicitRowHeight.getOpt());
}
effectiveCellBPD = Math.max(effectiveCellBPD, primary.getContentLength());
int borderWidths = primary.getBeforeAfterBorderWidth();
int padding = 0;
CommonBorderPaddingBackground cbpb = primary.getCell()
.getCommonBorderPaddingBackground();
padding += cbpb.getPaddingBefore(false, primary.getCellLM());
padding += cbpb.getPaddingAfter(false, primary.getCellLM());
int effRowHeight = effectiveCellBPD + padding + borderWidths;
for (int prev = rgi - 1; prev >= rgi - gu.getRowSpanIndex(); prev--) {
effRowHeight -= rowHeights[prev].getOpt();
}
if (effRowHeight > rowHeights[rgi].getMin()) {
// This is the new height of the (grid) row
rowHeights[rgi] = rowHeights[rgi].extendMinimum(effRowHeight);
}
}
}

row.setHeight(rowHeights[rgi]);
row.setExplicitHeight(explicitRowHeight);
// TODO re-enable and improve after clarification
//See http://markmail.org/message/h25ycwwu7qglr4k4
// if (maxCellBPD > row.getExplicitHeight().max) {
//old:
// log.warn(FONode.decorateWithContextInfo(
// "The contents of row " + (row.getIndex() + 1)
// + " are taller than they should be (there is a"
// + " block-progression-dimension or height constraint
// + " on the indicated row)."
// + " Due to its contents the row grows"
// + " to " + maxCellBPD + " millipoints, but the row shouldn't get"
// + " any taller than " + row.getExplicitHeight() + " millipoints.",
// row.getTableRow()));
//new (with events):
// BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Factory.create(
// tableRow.getUserAgent().getEventBroadcaster());
// eventProducer.rowTooTall(this, row.getIndex() + 1,
// maxCellBPD, row.getExplicitHeight().max, tableRow.getLocator());
// }
}
}
}
Loading

0 comments on commit bc7f88e

Please sign in to comment.