From a915c74aa4d3bcad9448d1808e5baba10ba91e24 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Tue, 17 Apr 2012 16:15:44 +0000 Subject: Bugzilla #53094: Convert block container overflow exception to event model, improving overflow property behavior. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1327157 13f79535-47bb-0310-9956-ffa450edef68 --- test/events/inline-level.fo | 6 ++---- test/events/viewport-overflow.fo | 18 ++++++++++++++++++ .../org/apache/fop/events/EventProcessingTestCase.java | 12 ++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 test/events/viewport-overflow.fo (limited to 'test') diff --git a/test/events/inline-level.fo b/test/events/inline-level.fo index 26a00acff..e415891ac 100644 --- a/test/events/inline-level.fo +++ b/test/events/inline-level.fo @@ -2,16 +2,14 @@ + page-height="420pt" page-width="100pt" margin="10pt"> The following line overflows its container: - - ThisLineOverflowsItsContainer - + ThisLineOverflowsItsContainer diff --git a/test/events/viewport-overflow.fo b/test/events/viewport-overflow.fo new file mode 100644 index 000000000..ac9dc76bb --- /dev/null +++ b/test/events/viewport-overflow.fo @@ -0,0 +1,18 @@ + + + + + + + + + + + abcdefghijklmnopqrstuvwxyz + + + abc def ghi jkl mno pqr stu vwx yz + + + + diff --git a/test/java/org/apache/fop/events/EventProcessingTestCase.java b/test/java/org/apache/fop/events/EventProcessingTestCase.java index 8219fa71e..1d38d4ccb 100644 --- a/test/java/org/apache/fop/events/EventProcessingTestCase.java +++ b/test/java/org/apache/fop/events/EventProcessingTestCase.java @@ -124,4 +124,16 @@ public class EventProcessingTestCase { doTest("inline-level.fo", InlineLevelEventProducer.class.getName() + ".lineOverflows"); } + + @Test + public void testViewportIPDOverflow() throws FOPException, TransformerException, IOException, + SAXException { + doTest("viewport-overflow.fo", BlockLevelEventProducer.class.getName() + ".viewportIPDOverflow"); + } + + @Test + public void testViewportBPDOverflow() throws FOPException, TransformerException, IOException, + SAXException { + doTest("viewport-overflow.fo", BlockLevelEventProducer.class.getName() + ".viewportBPDOverflow"); + } } -- cgit v1.2.3 From f397b576a8c874150e2e3efc2970de0fc1ce3e9f Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Tue, 17 Apr 2012 19:49:33 +0000 Subject: Bugzilla #53097: Ensure writing-mode specified on fo:table is used to determine writing mode of table and its descendants. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1327244 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/flow/table/Table.java | 42 +++++++++-- status.xml | 5 +- .../fop/fo/properties/PropertyListMocks.java | 4 ++ .../table-column_column-progression-rl.xml | 82 --------------------- .../table-column_column-progression-rl_1.xml | 83 ++++++++++++++++++++++ .../table-column_column-progression-rl_2.xml | 83 ++++++++++++++++++++++ 6 files changed, 210 insertions(+), 89 deletions(-) delete mode 100644 test/layoutengine/standard-testcases/table-column_column-progression-rl.xml create mode 100644 test/layoutengine/standard-testcases/table-column_column-progression-rl_1.xml create mode 100644 test/layoutengine/standard-testcases/table-column_column-progression-rl_2.xml (limited to 'test') diff --git a/src/java/org/apache/fop/fo/flow/table/Table.java b/src/java/org/apache/fop/fo/flow/table/Table.java index e599fc8c5..304996f1c 100644 --- a/src/java/org/apache/fop/fo/flow/table/Table.java +++ b/src/java/org/apache/fop/fo/flow/table/Table.java @@ -40,12 +40,16 @@ import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.LengthPairProperty; import org.apache.fop.fo.properties.LengthRangeProperty; import org.apache.fop.fo.properties.TableColLength; +import org.apache.fop.traits.Direction; +import org.apache.fop.traits.WritingMode; +import org.apache.fop.traits.WritingModeTraits; +import org.apache.fop.traits.WritingModeTraitsGetter; /** * Class modelling the * fo:table object. */ -public class Table extends TableFObj implements ColumnNumberManagerHolder, BreakPropertySet, +public class Table extends TableFObj implements ColumnNumberManagerHolder, BreakPropertySet, WritingModeTraitsGetter, CommonAccessibilityHolder { // The value of FO traits (refined properties) that apply to fo:table. @@ -64,7 +68,7 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break private int tableLayout; private int tableOmitFooterAtBreak; private int tableOmitHeaderAtBreak; - private int writingMode; + private WritingModeTraits writingModeTraits; // Unused but valid items, commented out for performance: // private CommonAural commonAural; // private CommonRelativePosition commonRelativePosition; @@ -131,7 +135,8 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break tableLayout = pList.get(PR_TABLE_LAYOUT).getEnum(); tableOmitFooterAtBreak = pList.get(PR_TABLE_OMIT_FOOTER_AT_BREAK).getEnum(); tableOmitHeaderAtBreak = pList.get(PR_TABLE_OMIT_HEADER_AT_BREAK).getEnum(); - writingMode = pList.get(PR_WRITING_MODE).getEnum(); + writingModeTraits = new WritingModeTraits + ( WritingMode.valueOf(pList.get(PR_WRITING_MODE).getEnum()) ); //Bind extension properties widowContentLimit = pList.get(PR_X_WIDOW_CONTENT_LIMIT).getLength(); @@ -516,9 +521,34 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break return borderSeparation; } - /** @return the "writing-mode" FO trait */ - public int getWritingMode() { - return writingMode; + /** {@inheritDoc} */ + public Direction getInlineProgressionDirection() { + return writingModeTraits.getInlineProgressionDirection(); + } + + /** {@inheritDoc} */ + public Direction getBlockProgressionDirection() { + return writingModeTraits.getBlockProgressionDirection(); + } + + /** {@inheritDoc} */ + public Direction getColumnProgressionDirection() { + return writingModeTraits.getColumnProgressionDirection(); + } + + /** {@inheritDoc} */ + public Direction getRowProgressionDirection() { + return writingModeTraits.getRowProgressionDirection(); + } + + /** {@inheritDoc} */ + public Direction getShiftDirection() { + return writingModeTraits.getShiftDirection(); + } + + /** {@inheritDoc} */ + public WritingMode getWritingMode() { + return writingModeTraits.getWritingMode(); } /** @return the "fox:widow-content-limit" extension FO trait */ diff --git a/status.xml b/status.xml index 57df34094..413ecfac1 100644 --- a/status.xml +++ b/status.xml @@ -62,7 +62,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> - + + Ensure writing-mode specified on fo:table is used to determine writing mode of table and its descendants. + + Convert block container overflow exception to event model, improving overflow property behavior. diff --git a/test/java/org/apache/fop/fo/properties/PropertyListMocks.java b/test/java/org/apache/fop/fo/properties/PropertyListMocks.java index 380f6e5a8..f364c9034 100644 --- a/test/java/org/apache/fop/fo/properties/PropertyListMocks.java +++ b/test/java/org/apache/fop/fo/properties/PropertyListMocks.java @@ -69,6 +69,10 @@ public final class PropertyListMocks { final Property borderCollapseProperty = mock(Property.class); when(borderCollapseProperty.getEnum()).thenReturn(Constants.EN_SEPARATE); when(mockPList.get(Constants.PR_BORDER_COLLAPSE)).thenReturn(borderCollapseProperty); + + final Property writingModeProperty = mock(Property.class); + when(writingModeProperty.getEnum()).thenReturn(Constants.EN_LR_TB); + when(mockPList.get(Constants.PR_WRITING_MODE)).thenReturn(writingModeProperty); } catch (PropertyException e) { throw new RuntimeException(e); } diff --git a/test/layoutengine/standard-testcases/table-column_column-progression-rl.xml b/test/layoutengine/standard-testcases/table-column_column-progression-rl.xml deleted file mode 100644 index 4f6b3d53a..000000000 --- a/test/layoutengine/standard-testcases/table-column_column-progression-rl.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - -

- This test checks table column progression with right-to-left writing mode. The first column - should be to the right of the second column; the second column should be to the right of the - third column. The columns should be colored red, yellow, orange from right to left. -

-
- - - - - - - - - - - - - - - - - cell1 - - - cell2 - - - cell3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/test/layoutengine/standard-testcases/table-column_column-progression-rl_1.xml b/test/layoutengine/standard-testcases/table-column_column-progression-rl_1.xml new file mode 100644 index 000000000..79db99a45 --- /dev/null +++ b/test/layoutengine/standard-testcases/table-column_column-progression-rl_1.xml @@ -0,0 +1,83 @@ + + + + + +

+ This test checks table column progression with right-to-left writing mode when writing-mode + is specified on fo:page-sequence. The first column should be to the right of the second column; the + second column should be to the right of the third column. The columns should be colored red, + yellow, orange from right to left. +

+
+ + + + + + + + + + + + + + + + + cell1 + + + cell2 + + + cell3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/table-column_column-progression-rl_2.xml b/test/layoutengine/standard-testcases/table-column_column-progression-rl_2.xml new file mode 100644 index 000000000..e7230a574 --- /dev/null +++ b/test/layoutengine/standard-testcases/table-column_column-progression-rl_2.xml @@ -0,0 +1,83 @@ + + + + + +

+ This test checks table column progression with right-to-left writing mode when writing-mode + is specified on fo:table. The first column should be to the right of the second column; the + second column should be to the right of the third column. The columns should be colored red, + yellow, orange from right to left. +

+
+ + + + + + + + + + + + + + + + + cell1 + + + cell2 + + + cell3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-- cgit v1.2.3 From e533832b11cea16e8599c549f015cab12c653f66 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Tue, 17 Apr 2012 21:34:52 +0000 Subject: Bugzilla #53086: Ensure that table footer and header are included in bididirectional resolution. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1327291 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/flow/table/Table.java | 23 ++++++ status.xml | 3 + .../standard-testcases/table_writing-mode_rl.xml | 91 ++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 test/layoutengine/standard-testcases/table_writing-mode_rl.xml (limited to 'test') diff --git a/src/java/org/apache/fop/fo/flow/table/Table.java b/src/java/org/apache/fop/fo/flow/table/Table.java index 304996f1c..a574723b1 100644 --- a/src/java/org/apache/fop/fo/flow/table/Table.java +++ b/src/java/org/apache/fop/fo/flow/table/Table.java @@ -20,11 +20,14 @@ package org.apache.fop.fo.flow.table; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Stack; import org.xml.sax.Locator; import org.apache.fop.apps.FOPException; +import org.apache.fop.complexscripts.bidi.DelimitedTextRange; import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.ValidationPercentBaseContext; import org.apache.fop.fo.FONode; @@ -597,4 +600,24 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder, Break RowGroupBuilder getRowGroupBuilder() { return rowGroupBuilder; } + + @Override + protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { + // header sub-tree + TableHeader header = getTableHeader(); + if ( header != null ) { + ranges = header.collectDelimitedTextRanges ( ranges ); + } + // footer sub-tree + TableFooter footer = getTableFooter(); + if ( footer != null ) { + ranges = footer.collectDelimitedTextRanges ( ranges ); + } + // body sub-tree + for ( Iterator it = getChildNodes(); ( it != null ) && it.hasNext();) { + ranges = ( (FONode) it.next() ).collectDelimitedTextRanges ( ranges ); + } + return ranges; + } + } diff --git a/status.xml b/status.xml index 413ecfac1..67e2fb973 100644 --- a/status.xml +++ b/status.xml @@ -62,6 +62,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Ensure that table footer and header are included in bididirectional resolution. + Ensure writing-mode specified on fo:table is used to determine writing mode of table and its descendants. diff --git a/test/layoutengine/standard-testcases/table_writing-mode_rl.xml b/test/layoutengine/standard-testcases/table_writing-mode_rl.xml new file mode 100644 index 000000000..65927ec48 --- /dev/null +++ b/test/layoutengine/standard-testcases/table_writing-mode_rl.xml @@ -0,0 +1,91 @@ + + + + + +

+ This test checks table header, footer, and body cells all respect writing-mode="rl" specified on table. See also Bugzilla #53086. +

+
+ + + + + + + + + + + + + + + HEADER ROW + + + ABC + + + DEF + + + + + + + FOOTER ROW + + + ABC + + + DEF + + + + + + + BODY ROW + + + ABC + + + DEF + + + + + + + + + + + + + + + + + + + +
-- cgit v1.2.3 From 46917ef59fd0ffbbcccb16d57118a92da3dc1e0d Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Fri, 20 Apr 2012 21:26:43 +0000 Subject: Bugzilla #53101: Ensure that table cell spanning works in right-to-left writing mode. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1328515 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/layoutmgr/table/ColumnSetup.java | 9 ++- .../org/apache/fop/layoutmgr/table/RowPainter.java | 2 +- .../layoutmgr/table/TableContentLayoutManager.java | 7 +- status.xml | 3 + .../table-column_column-progression-rl_3.xml | 89 ++++++++++++++++++++++ 5 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 test/layoutengine/standard-testcases/table-column_column-progression-rl_3.xml (limited to 'test') diff --git a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java index aaccbd0d3..b0ad22386 100644 --- a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java +++ b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java @@ -245,13 +245,14 @@ public class ColumnSetup { * the left-most column; otherwise, the first column is the left-most * column. * @param col column index (1 is first column) + * @param nrColSpan number columns spanned (for calculating offset in rtl mode) * @param context the context for percentage based calculations * @return the X offset of the requested column */ - public int getXOffset(int col, PercentBaseContext context) { + public int getXOffset(int col, int nrColSpan, PercentBaseContext context) { // TODO handle vertical WMs [GA] if ( (wmTraits != null) && (wmTraits.getColumnProgressionDirection() == Direction.RL) ) { - return getXOffsetRTL(col, context); + return getXOffsetRTL(col, nrColSpan, context); } else { return getXOffsetLTR(col, context); } @@ -262,9 +263,9 @@ public class ColumnSetup { * column; i.e., those columns whose column numbers are greater than the * specified column number. */ - private int getXOffsetRTL(int col, PercentBaseContext context) { + private int getXOffsetRTL(int col, int nrColSpan, PercentBaseContext context) { int xoffset = 0; - for (int i = col, nc = colWidths.size(); ++i < nc;) { + for (int i = (col + nrColSpan - 1), nc = colWidths.size(); ++i < nc;) { int effCol = i; if (colWidths.get(effCol) != null) { xoffset += ((Length) colWidths.get(effCol)).getValue(context); diff --git a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java index f6c831b3f..955dafabd 100644 --- a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java +++ b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java @@ -468,7 +468,7 @@ class RowPainter { block.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); block.setIPD(ipd); block.setBPD(bpd); - block.setXOffset(tclm.getXOffsetOfGridUnit(colIndex) + block.setXOffset(tclm.getXOffsetOfGridUnit(colIndex, 1) + (borderStart.getRetainedWidth() / 2)); block.setYOffset(getRowOffset(rowIndex) - (borderBefore.getRetainedWidth() / 2)); diff --git a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java index db5b4736c..f5e7500e2 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java @@ -317,16 +317,17 @@ public class TableContentLayoutManager implements PercentBaseContext { * @return the requested X offset */ protected int getXOffsetOfGridUnit(PrimaryGridUnit gu) { - return getXOffsetOfGridUnit(gu.getColIndex()); + return getXOffsetOfGridUnit(gu.getColIndex(), gu.getCell().getNumberColumnsSpanned()); } /** * Returns the X offset of the grid unit in the given column. * @param colIndex the column index (zero-based) + * @param nrColSpan number columns spanned * @return the requested X offset */ - protected int getXOffsetOfGridUnit(int colIndex) { - return startXOffset + getTableLM().getColumns().getXOffset(colIndex + 1, getTableLM()); + protected int getXOffsetOfGridUnit(int colIndex, int nrColSpan) { + return startXOffset + getTableLM().getColumns().getXOffset(colIndex + 1, nrColSpan, getTableLM()); } /** diff --git a/status.xml b/status.xml index 67e2fb973..13c5bc36f 100644 --- a/status.xml +++ b/status.xml @@ -62,6 +62,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Ensure that table cell spanning works in right-to-left writing mode. + Ensure that table footer and header are included in bididirectional resolution. diff --git a/test/layoutengine/standard-testcases/table-column_column-progression-rl_3.xml b/test/layoutengine/standard-testcases/table-column_column-progression-rl_3.xml new file mode 100644 index 000000000..0b39606f7 --- /dev/null +++ b/test/layoutengine/standard-testcases/table-column_column-progression-rl_3.xml @@ -0,0 +1,89 @@ + + + + + +

+ This test checks table column progression with right-to-left writing mode when using multiple + column spans. See also bugzilla #53103. +

+
+ + + + + + + + + + + + + + header-R1;C1-span2 + + + header-R1;C2 + + + header-R1;C3 + + + + + + + body-R2;C1 + + + body-R2;C2 + + + body-R2;C3 + + + + + body-R3;C1-span3 + + + body-R3;C2 + + + + + + + + + + + + + + + + + + + + + + +
-- cgit v1.2.3 From b8f0ffa310d6cefaa47da2287f5f22c448fd66b8 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Tue, 24 Apr 2012 17:15:15 +0000 Subject: Bugzilla #50196: Add test for basic-link with padding. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1329865 13f79535-47bb-0310-9956-ffa450edef68 --- status.xml | 4 ++ .../basic-link_padding_bug50196.xml | 45 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/layoutengine/standard-testcases/basic-link_padding_bug50196.xml (limited to 'test') diff --git a/status.xml b/status.xml index 05c8e8ab5..1e5ea7dfb 100644 --- a/status.xml +++ b/status.xml @@ -53,6 +53,7 @@ + @@ -62,6 +63,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Add test for basic-link with padding. + Improve property function argument parsing, specifically, better separate required, optional, and variable arguments and the handling of optional argument defaults. Regularize property function class names. diff --git a/test/layoutengine/standard-testcases/basic-link_padding_bug50196.xml b/test/layoutengine/standard-testcases/basic-link_padding_bug50196.xml new file mode 100644 index 000000000..e7039bc02 --- /dev/null +++ b/test/layoutengine/standard-testcases/basic-link_padding_bug50196.xml @@ -0,0 +1,45 @@ + + + + + +

+ Bugzilla #50196: padding-start on basic-link causes exception +

+
+ + + + + + + + + + + test + + + + + + + + + +
-- cgit v1.2.3 From 953e762e1b5dcb2cb31b6ca8a87110018c9151de Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Fri, 4 May 2012 16:52:35 +0000 Subject: Bugzilla #45715: Break before (break-before) not respected on blocks nested in inlines. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1334058 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/layoutmgr/AbstractLayoutManager.java | 3 +- .../fop/layoutmgr/BlockContainerLayoutManager.java | 9 +++- .../apache/fop/layoutmgr/BlockLayoutManager.java | 8 +++- .../fop/layoutmgr/BlockStackingLayoutManager.java | 24 +--------- .../org/apache/fop/layoutmgr/BreakOpportunity.java | 36 +++++++++++++++ .../fop/layoutmgr/BreakOpportunityHelper.java | 54 ++++++++++++++++++++++ .../fop/layoutmgr/inline/InlineLayoutManager.java | 7 +++ .../inline/InlineStackingLayoutManager.java | 11 ++++- status.xml | 17 ++++--- .../block-break-inline-break-before.xml | 38 +++++++++++++++ .../block-inline-break-before.xml | 40 ++++++++++++++++ .../block-inline-inline-break-before.xml | 40 ++++++++++++++++ 12 files changed, 249 insertions(+), 38 deletions(-) create mode 100644 src/java/org/apache/fop/layoutmgr/BreakOpportunity.java create mode 100644 src/java/org/apache/fop/layoutmgr/BreakOpportunityHelper.java create mode 100644 test/layoutengine/standard-testcases/block-break-inline-break-before.xml create mode 100644 test/layoutengine/standard-testcases/block-inline-break-before.xml create mode 100644 test/layoutengine/standard-testcases/block-inline-inline-break-before.xml (limited to 'test') diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java index d227b7060..0089f228f 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -41,8 +41,7 @@ import org.apache.fop.fo.flow.RetrieveMarker; /** * The base class for most LayoutManagers. */ -public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager - implements Constants { +public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager implements Constants { /** logging instance */ private static Log log = LogFactory.getLog(AbstractLayoutManager.class); diff --git a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index 8b656a753..adce89ac0 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -44,8 +44,8 @@ import org.apache.fop.traits.SpaceVal; /** * LayoutManager for a block-container FO. */ -public class BlockContainerLayoutManager extends BlockStackingLayoutManager - implements ConditionalElementListener { +public class BlockContainerLayoutManager extends BlockStackingLayoutManager implements + ConditionalElementListener, BreakOpportunity { /** * logging instance @@ -1043,6 +1043,11 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager } return true; } + + public int getBreakBefore() { + return BreakOpportunityHelper.getBreakBefore(this); + } + } diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 9c3639f93..03b2d380c 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -43,8 +43,8 @@ import org.apache.fop.traits.SpaceVal; /** * LayoutManager for a block FO. */ -public class BlockLayoutManager extends BlockStackingLayoutManager - implements ConditionalElementListener { +public class BlockLayoutManager extends BlockStackingLayoutManager implements ConditionalElementListener, + BreakOpportunity { /** logging instance */ private static Log log = LogFactory.getLog(BlockLayoutManager.class); @@ -504,4 +504,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager return true; } + public int getBreakBefore() { + return BreakOpportunityHelper.getBreakBefore(this); + } + } diff --git a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java index 403bd6f68..78ab6711a 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java @@ -38,7 +38,6 @@ import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.layoutmgr.inline.InlineLayoutManager; import org.apache.fop.traits.MinOptMax; -import org.apache.fop.util.BreakUtil; import org.apache.fop.util.ListUtil; /** @@ -1036,7 +1035,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager * @return true if an element has been added due to a break-before. */ protected boolean addKnuthElementsForBreakBefore(List returnList, LayoutContext context) { - int breakBefore = getBreakBefore(); + int breakBefore = BreakOpportunityHelper.getBreakBefore(this); if (breakBefore == EN_PAGE || breakBefore == EN_COLUMN || breakBefore == EN_EVEN_PAGE @@ -1050,27 +1049,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager } } - /** - * Returns the break-before value of the current formatting object. - * @return the break-before value (Constants.EN_*) - */ - private int getBreakBefore() { - int breakBefore = EN_AUTO; - if (fobj instanceof BreakPropertySet) { - breakBefore = ((BreakPropertySet)fobj).getBreakBefore(); - } - if (true /* uncomment to only partially merge: && breakBefore != EN_AUTO*/) { - LayoutManager lm = getChildLM(); - //It is assumed this is only called when the first LM is active. - if (lm instanceof BlockStackingLayoutManager) { - BlockStackingLayoutManager bslm = (BlockStackingLayoutManager)lm; - breakBefore = BreakUtil.compareBreakClasses( - breakBefore, bslm.getBreakBefore()); - } - } - return breakBefore; - } - /** * Creates Knuth elements for break-after and adds them to the return list. * @param returnList return list to add the additional elements to diff --git a/src/java/org/apache/fop/layoutmgr/BreakOpportunity.java b/src/java/org/apache/fop/layoutmgr/BreakOpportunity.java new file mode 100644 index 000000000..668f112c9 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/BreakOpportunity.java @@ -0,0 +1,36 @@ +/* + * 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; + +/** + * Defines methods to evaluate break opportunities at a particular location in the tree of + * layout managers. + */ +public interface BreakOpportunity { + + /** + * Returns the highest priority break-before value on this layout manager or its + * relevant descendants. + * + * @return the break-before value (Constants.EN_*) + */ + int getBreakBefore(); + +} diff --git a/src/java/org/apache/fop/layoutmgr/BreakOpportunityHelper.java b/src/java/org/apache/fop/layoutmgr/BreakOpportunityHelper.java new file mode 100644 index 000000000..a3992567f --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/BreakOpportunityHelper.java @@ -0,0 +1,54 @@ +/* + * 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; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.properties.BreakPropertySet; +import org.apache.fop.util.BreakUtil; + +/** + * Helper implementations of the {@link BreakOpportunity} methods. + */ +public final class BreakOpportunityHelper { + + private BreakOpportunityHelper() { } + + /** + * Returns the break opportunity before the given layout manager. There is a break + * opportunity if the LM's FO has the break-before property set, or if there is a + * break opportunity before its first child LM. + * + * @return the break-before value (Constants.EN_*) + */ + public static int getBreakBefore(AbstractLayoutManager layoutManager) { + int breakBefore = Constants.EN_AUTO; + if (layoutManager.getFObj() instanceof BreakPropertySet) { + breakBefore = ((BreakPropertySet) layoutManager.getFObj()).getBreakBefore(); + } + LayoutManager childLM = layoutManager.getChildLM(); + // It is assumed this is only called when the first LM is active. + if (childLM instanceof BreakOpportunity) { + BreakOpportunity bo = (BreakOpportunity) childLM; + breakBefore = BreakUtil.compareBreakClasses(breakBefore, bo.getBreakBefore()); + } + return breakBefore; + } + +} diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java index 1eb91e0ab..e87b29b2d 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java @@ -388,6 +388,13 @@ public class InlineLayoutManager extends InlineStackingLayoutManager { } lastSequence = ListUtil.getLast(returnList); lastChildLM = curLM; + // the context used to create this childLC above was applied a LayoutContext.SUPPRESS_BREAK_BEFORE + // in the getNextChildElements() method of the parent BlockLayoutManger; as a consequence all + // line breaks in blocks nested inside the inline associated with this ILM are being supressed; + // here we revert that supression; we do not need to do that for the first element since that + // is handled by the getBreakBefore() method of the wrapping BlockStackingLayoutManager. + // Note: this fix seems to work but is far from being the ideal way to do this + childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE, false); } if (lastSequence != null) { diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java index 4a203d55e..3e9b85742 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java @@ -28,6 +28,8 @@ import org.apache.fop.area.inline.Space; import org.apache.fop.fo.FObj; import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.layoutmgr.AbstractLayoutManager; +import org.apache.fop.layoutmgr.BreakOpportunity; +import org.apache.fop.layoutmgr.BreakOpportunityHelper; import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.NonLeafPosition; @@ -39,8 +41,8 @@ import org.apache.fop.traits.MinOptMax; * which stack children in the inline direction, such as Inline or * Line. It should not be instantiated directly. */ -public abstract class InlineStackingLayoutManager extends AbstractLayoutManager - implements InlineLevelLayoutManager { +public abstract class InlineStackingLayoutManager extends AbstractLayoutManager implements + InlineLevelLayoutManager, BreakOpportunity { /** * Size of border and padding in BPD (ie, before and after). @@ -385,4 +387,9 @@ public abstract class InlineStackingLayoutManager extends AbstractLayoutManager return returnList; } + + public int getBreakBefore() { + return BreakOpportunityHelper.getBreakBefore(this); + } + } diff --git a/status.xml b/status.xml index 7ccdc9557..72fcb6229 100644 --- a/status.xml +++ b/status.xml @@ -63,7 +63,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> - + + Break before (break-before) not respected on blocks nested in inlines. + + Fix for XGC when rendering PostScript using SVG being drawn upside down when using a custom affine transform. @@ -85,20 +88,20 @@ Improve property function argument parsing, specifically, better separate required, optional, and variable arguments and the handling of optional argument defaults. Regularize property function class names. - + Don't restart layout unless abs(ipd difference) > 1 in order to prevent rounding issues from triggering false restart. Removing experimental feature that violates XSL-FO and Unicode semantics by misinterpreting Basic Latin code points. Users must use private use codepoints to access font specific character mappings that have no assigned Unicode code point. See bug 50492. - + Ensure that table cell spanning works in right-to-left writing mode. - + Ensure that table footer and header are included in bididirectional resolution. - + Ensure writing-mode specified on fo:table is used to determine writing mode of table and its descendants. @@ -113,13 +116,13 @@ Prevent NPE on use of unsupported collapse-with-precedence; fall back to collapse. Fix checkstyle errors from prior commit. - + Ensure square image is appropriately scaled. Invoke JVM in headless mode from FOP command scripts and JS shell to prevent stealing focus from GUI applications. - + Take leading derived space before/after into account when computing rows for TXT renderer. diff --git a/test/layoutengine/standard-testcases/block-break-inline-break-before.xml b/test/layoutengine/standard-testcases/block-break-inline-break-before.xml new file mode 100644 index 000000000..627862aa1 --- /dev/null +++ b/test/layoutengine/standard-testcases/block-break-inline-break-before.xml @@ -0,0 +1,38 @@ + + + + + +

This tests that two breaks across an inline are treated as one.

+
+ + + + + + + + + + one + + + two + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/block-inline-break-before.xml b/test/layoutengine/standard-testcases/block-inline-break-before.xml new file mode 100644 index 000000000..64b3694a1 --- /dev/null +++ b/test/layoutengine/standard-testcases/block-inline-break-before.xml @@ -0,0 +1,40 @@ + + + + + +

This test checks basic breaks.

+
+ + + + + + + + + + one + + + two + three + + + + + + + + + + + +
diff --git a/test/layoutengine/standard-testcases/block-inline-inline-break-before.xml b/test/layoutengine/standard-testcases/block-inline-inline-break-before.xml new file mode 100644 index 000000000..a44118b51 --- /dev/null +++ b/test/layoutengine/standard-testcases/block-inline-inline-break-before.xml @@ -0,0 +1,40 @@ + + + + + +

This tests a break inside nested inlines.

+
+ + + + + + + + + + one + + + + two + + + + + + + + + + + +
-- cgit v1.2.3 From c46fafb223e69046ffba3dd8c46314058f8091f2 Mon Sep 17 00:00:00 2001 From: Mehdi Houshmand Date: Fri, 11 May 2012 13:14:17 +0000 Subject: Changed the way AFP PTOCA TransparentData control sequences are written so that they end on character byte boundaries git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1337142 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/afp/fonts/CharactersetEncoder.java | 51 ++++----- .../org/apache/fop/afp/modca/AxisOrientation.java | 82 +++++++++++++++ .../org/apache/fop/afp/modca/IncludeObject.java | 69 +------------ src/java/org/apache/fop/afp/modca/Rotation.java | 46 +++++++++ .../org/apache/fop/afp/ptoca/PtocaBuilder.java | 115 +++++---------------- .../org/apache/fop/afp/ptoca/PtocaConstants.java | 2 +- .../afp/ptoca/TransparentDataControlSequence.java | 89 ++++++++++++++++ .../TransparentDataControlSequenceTestCase.java | 73 +++++++++++++ 8 files changed, 340 insertions(+), 187 deletions(-) create mode 100644 src/java/org/apache/fop/afp/modca/AxisOrientation.java create mode 100644 src/java/org/apache/fop/afp/modca/Rotation.java create mode 100644 src/java/org/apache/fop/afp/ptoca/TransparentDataControlSequence.java create mode 100644 test/java/org/apache/fop/afp/ptoca/TransparentDataControlSequenceTestCase.java (limited to 'test') diff --git a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java index 229123a82..6d85c0f52 100644 --- a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java +++ b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java @@ -105,9 +105,9 @@ public abstract class CharactersetEncoder { @Override EncodedChars getEncodedChars(byte[] byteArray, int length) { if (byteArray[0] == 0x0E && byteArray[length - 1] == 0x0F) { - return new EncodedChars(byteArray, 1, length - 2); + return new EncodedChars(byteArray, 1, length - 2, true); } - return new EncodedChars(byteArray); + return new EncodedChars(byteArray, true); } } @@ -123,7 +123,7 @@ public abstract class CharactersetEncoder { @Override EncodedChars getEncodedChars(byte[] byteArray, int length) { - return new EncodedChars(byteArray); + return new EncodedChars(byteArray, false); } } @@ -145,36 +145,25 @@ public abstract class CharactersetEncoder { /** * A container for encoded character bytes */ - public static final class EncodedChars { + public static class EncodedChars { private final byte[] bytes; - private final int offset; - private final int length; + private final boolean isDBCS; - private EncodedChars(byte[] bytes, int offset, int length) { - if (offset < 0) { - throw new IllegalArgumentException(); - } - - if (length < 0) { - throw new IllegalArgumentException(); - } - - if (offset + length > bytes.length) { + private EncodedChars(byte[] bytes, int offset, int length, boolean isDBCS) { + if (offset < 0 || length < 0 || offset + length > bytes.length) { throw new IllegalArgumentException(); } - this.bytes = bytes; - this.offset = offset; - this.length = length; + this.isDBCS = isDBCS; } - private EncodedChars(byte[] bytes) { - this(bytes, 0, bytes.length); + private EncodedChars(byte[] bytes, boolean isDBCS) { + this(bytes, 0, bytes.length, isDBCS); } /** @@ -186,18 +175,9 @@ public abstract class CharactersetEncoder { * @throws IOException if an I/O error occurs */ public void writeTo(OutputStream out, int offset, int length) throws IOException { - if (offset < 0) { + if (offset < 0 || length < 0 || offset + length > bytes.length) { throw new IllegalArgumentException(); } - - if (length < 0) { - throw new IllegalArgumentException(); - } - - if (offset + length > this.length) { - throw new IllegalArgumentException(); - } - out.write(bytes, this.offset + offset, length); } @@ -210,6 +190,15 @@ public abstract class CharactersetEncoder { return length; } + /** + * Indicates whether or not the EncodedChars object wraps double byte characters. + * + * @return true if the wrapped characters are double byte (DBCSs) + */ + public boolean isDBCS() { + return isDBCS; + } + /** * The bytes * diff --git a/src/java/org/apache/fop/afp/modca/AxisOrientation.java b/src/java/org/apache/fop/afp/modca/AxisOrientation.java new file mode 100644 index 000000000..a017fe5e3 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/AxisOrientation.java @@ -0,0 +1,82 @@ +/* + * 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.afp.modca; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * Represents the 4 bytes that specify the axis-area rotation reference coordinate system + */ +public enum AxisOrientation { + + RIGHT_HANDED_0(Rotation.ROTATION_0, Rotation.ROTATION_90), + RIGHT_HANDED_90(Rotation.ROTATION_90, Rotation.ROTATION_180), + RIGHT_HANDED_180(Rotation.ROTATION_180, Rotation.ROTATION_270), + RIGHT_HANDED_270(Rotation.ROTATION_270, Rotation.ROTATION_0); + + /** + * The object area's X-axis rotation from the X axis of the reference coordinate system + */ + private final Rotation xoaOrent; + /** + * The object area's Y-axis rotation from the Y axis of the reference coordinate system + */ + private final Rotation yoaOrent; + + public void writeTo(byte[] out, int offset) { + xoaOrent.writeTo(out, offset); + yoaOrent.writeTo(out, offset + 2); + } + + private AxisOrientation(Rotation xoaOrent, Rotation yoaOrent) { + this.xoaOrent = xoaOrent; + this.yoaOrent = yoaOrent; + } + + /** + * Writes the axis orientation area bytes to the output stream. + * + * @param stream the output stream to write to + * @throws IOException if an I/O error occurs + */ + public void writeTo(OutputStream stream) throws IOException { + byte[] data = new byte[4]; + writeTo(data, 0); + stream.write(data); + } + + /** + * Gets the right-handed axis orientation object for a given orientation in degrees. + * + * @param orientation the orientation in degrees + * @return the {@link AxisOrientation} object + */ + public static AxisOrientation getRightHandedAxisOrientationFor(int orientation) { + switch (orientation) { + case 0: return RIGHT_HANDED_0; + case 90: return RIGHT_HANDED_90; + case 180: return RIGHT_HANDED_180; + case 270: return RIGHT_HANDED_270; + default: throw new IllegalArgumentException( + "The orientation must be one of the values 0, 90, 180, 270"); + } + } +} diff --git a/src/java/org/apache/fop/afp/modca/IncludeObject.java b/src/java/org/apache/fop/afp/modca/IncludeObject.java index 68fa72688..4dca1b357 100644 --- a/src/java/org/apache/fop/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/afp/modca/IncludeObject.java @@ -67,7 +67,7 @@ public class IncludeObject extends AbstractNamedAFPObject { private int yoaOset = 0; /** the orientation of the referenced object */ - private ObjectAreaRotation oaOrent = ObjectAreaRotation.RIGHT_HANDED_0; + private AxisOrientation oaOrent = AxisOrientation.RIGHT_HANDED_0; /** the X-axis origin defined in the object */ private int xocaOset = -1; @@ -93,7 +93,7 @@ public class IncludeObject extends AbstractNamedAFPObject { * The orientation (0,90, 180, 270) */ public void setObjectAreaOrientation(int orientation) { - this.oaOrent = ObjectAreaRotation.objectAreaRotationFor(orientation); + this.oaOrent = AxisOrientation.getRightHandedAxisOrientationFor(orientation); } /** @@ -234,69 +234,4 @@ public class IncludeObject extends AbstractNamedAFPObject { addTriplet(new MeasurementUnitsTriplet(xRes, xRes)); } - /** - * Represents the 4 bytes that specify the area rotation reference coordinate system - * - */ - private enum ObjectAreaRotation { - - RIGHT_HANDED_0(Rotation.ROTATION_0, Rotation.ROTATION_90), - RIGHT_HANDED_90(Rotation.ROTATION_90, Rotation.ROTATION_180), - RIGHT_HANDED_180(Rotation.ROTATION_180, Rotation.ROTATION_270), - RIGHT_HANDED_270(Rotation.ROTATION_270, Rotation.ROTATION_0); - - /** - * The object area's X-axis rotation from the X axis of the reference coordinate system - */ - private final Rotation xoaOrent; - /** - * The object area's Y-axis rotation from the Y axis of the reference coordinate system - */ - private final Rotation yoaOrent; - - public void writeTo(byte[] out, int offset) { - xoaOrent.writeTo(out, offset); - yoaOrent.writeTo(out, offset + 2); - } - - ObjectAreaRotation(Rotation xoaOrent, Rotation yoaOrent) { - this.xoaOrent = xoaOrent; - this.yoaOrent = yoaOrent; - } - - private static ObjectAreaRotation objectAreaRotationFor(int orientation) { - switch (orientation) { - case 0: return RIGHT_HANDED_0; - case 90: return RIGHT_HANDED_90; - case 180: return RIGHT_HANDED_180; - case 270: return RIGHT_HANDED_270; - default: throw new IllegalArgumentException( - "The orientation must be one of the values 0, 90, 180, 270"); - } - } - } - - /** - * Represents a rotation value - * - */ - private enum Rotation { - - ROTATION_0(0), - ROTATION_90(0x2D), - ROTATION_180(0x5A), - ROTATION_270(0x87); - - private final byte firstByte; - - public void writeTo(byte[] out, int offset) { - out[offset] = firstByte; - out[offset + 1] = (byte)0; - } - - Rotation(int firstByte) { - this.firstByte = (byte) firstByte; - } - } - } diff --git a/src/java/org/apache/fop/afp/modca/Rotation.java b/src/java/org/apache/fop/afp/modca/Rotation.java new file mode 100644 index 000000000..a307e1cf9 --- /dev/null +++ b/src/java/org/apache/fop/afp/modca/Rotation.java @@ -0,0 +1,46 @@ +/* + * 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.afp.modca; + +/** + * Represents a rotation value + * + */ +public enum Rotation { + ROTATION_0(0), + ROTATION_90(0x2D), + ROTATION_180(0x5A), + ROTATION_270(0x87); + + private final byte firstByte; + + public void writeTo(byte[] out, int offset) { + out[offset] = firstByte; + out[offset + 1] = (byte)0; + } + + private Rotation(int firstByte) { + this.firstByte = (byte) firstByte; + } + + public byte getByte() { + return firstByte; + } +} diff --git a/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java b/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java index 1ea63c7f9..befd2cc1a 100644 --- a/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java +++ b/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java @@ -31,6 +31,8 @@ import org.apache.xmlgraphics.java2d.color.ColorUtil; import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; import org.apache.fop.afp.fonts.CharactersetEncoder.EncodedChars; +import org.apache.fop.afp.modca.AxisOrientation; +import org.apache.fop.afp.ptoca.TransparentDataControlSequence.TransparentData; /** * Generator class for PTOCA data structures. @@ -87,8 +89,10 @@ public abstract class PtocaBuilder implements PtocaConstants { baout.writeTo(out); } - private void writeByte(int data) { - baout.write(data); + private void writeBytes(int... data) { + for (int d : data) { + baout.write(d); + } } private void writeShort(int data) { @@ -123,7 +127,7 @@ public abstract class PtocaBuilder implements PtocaConstants { } newControlSequence(); - writeByte(font); + writeBytes(font); commit(chained(SCFL)); } @@ -187,26 +191,11 @@ public abstract class PtocaBuilder implements PtocaConstants { * @throws IOException if an I/O error occurs */ public void addTransparentData(EncodedChars encodedChars) throws IOException { - - // data size greater than TRANSPARENT_MAX_SIZE, so slice - int numTransData = encodedChars.getLength() / TRANSPARENT_DATA_MAX_SIZE; - int currIndex = 0; - for (int transDataCnt = 0; transDataCnt < numTransData; transDataCnt++) { - addTransparentDataChunk(encodedChars, currIndex, TRANSPARENT_DATA_MAX_SIZE); - currIndex += TRANSPARENT_DATA_MAX_SIZE; + for (TransparentData trn : new TransparentDataControlSequence(encodedChars)) { + newControlSequence(); + trn.writeTo(baout); + commit(chained(TRN)); } - int left = encodedChars.getLength() - currIndex; - addTransparentDataChunk(encodedChars, currIndex, left); - - } - - - - private void addTransparentDataChunk(EncodedChars encodedChars, int offset, int length) - throws IOException { - newControlSequence(); - encodedChars.writeTo(baout, offset, length); - commit(chained(TRN)); } /** @@ -222,7 +211,7 @@ public abstract class PtocaBuilder implements PtocaConstants { newControlSequence(); writeShort(length); // Rule length writeShort(width); // Rule width - writeByte(0); // Rule width fraction is always null. enough? + writeBytes(0); // Rule width fraction is always null. enough? commit(chained(DBR)); } @@ -239,7 +228,7 @@ public abstract class PtocaBuilder implements PtocaConstants { newControlSequence(); writeShort(length); // Rule length writeShort(width); // Rule width - writeByte(0); // Rule width fraction is always null. enough? + writeBytes(0); // Rule width fraction is always null. enough? commit(chained(DIR)); } @@ -260,32 +249,7 @@ public abstract class PtocaBuilder implements PtocaConstants { return; } newControlSequence(); - switch (orientation) { - case 90: - writeByte(0x2D); - writeByte(0x00); - writeByte(0x5A); - writeByte(0x00); - break; - case 180: - writeByte(0x5A); - writeByte(0x00); - writeByte(0x87); - writeByte(0x00); - break; - case 270: - writeByte(0x87); - writeByte(0x00); - writeByte(0x00); - writeByte(0x00); - break; - default: - writeByte(0x00); - writeByte(0x00); - writeByte(0x2D); - writeByte(0x00); - break; - } + AxisOrientation.getRightHandedAxisOrientationFor(orientation).writeTo(baout); commit(chained(STO)); this.currentOrientation = orientation; currentX = -1; @@ -317,55 +281,30 @@ public abstract class PtocaBuilder implements PtocaConstants { newControlSequence(); if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) { - writeByte(0x00); // Reserved; must be zero - writeByte(0x04); // Color space - 0x04 = CMYK - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(8); // Number of bits in component 1 - writeByte(8); // Number of bits in component 2 - writeByte(8); // Number of bits in component 3 - writeByte(8); // Number of bits in component 4 + // Color space - 0x04 = CMYK, all else are reserved and must be zero + writeBytes(0x00, 0x04, 0x00, 0x00, 0x00, 0x00); + writeBytes(8, 8, 8, 8); // Number of bits in component 1, 2, 3 & 4 respectively float[] comps = col.getColorComponents(null); assert comps.length == 4; for (int i = 0; i < 4; i++) { int component = Math.round(comps[i] * 255); - writeByte(component); + writeBytes(component); } } else if (cs instanceof CIELabColorSpace) { - writeByte(0x00); // Reserved; must be zero - writeByte(0x08); // Color space - 0x08 = CIELAB - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(8); // Number of bits in component 1 - writeByte(8); // Number of bits in component 2 - writeByte(8); // Number of bits in component 3 - writeByte(0); // Number of bits in component 4 + // Color space - 0x08 = CIELAB, all else are reserved and must be zero + writeBytes(0x00, 0x08, 0x00, 0x00, 0x00, 0x00); + writeBytes(8, 8, 8, 0); // Number of bits in component 1,2,3 & 4 //Sadly, 16 bit components don't seem to work float[] colorComponents = col.getColorComponents(null); int l = Math.round(colorComponents[0] * 255f); int a = Math.round(colorComponents[1] * 255f) - 128; int b = Math.round(colorComponents[2] * 255f) - 128; - writeByte(l); // L* - writeByte(a); // a* - writeByte(b); // b* + writeBytes(l, a, b); // l*, a* and b* } else { - writeByte(0x00); // Reserved; must be zero - writeByte(0x01); // Color space - 0x01 = RGB - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(0x00); // Reserved; must be zero - writeByte(8); // Number of bits in component 1 - writeByte(8); // Number of bits in component 2 - writeByte(8); // Number of bits in component 3 - writeByte(0); // Number of bits in component 4 - writeByte(col.getRed()); // Red intensity - writeByte(col.getGreen()); // Green intensity - writeByte(col.getBlue()); // Blue intensity + // Color space - 0x01 = RGB, all else are reserved and must be zero + writeBytes(0x00, 0x01, 0x00, 0x00, 0x00, 0x00); + writeBytes(8, 8, 8, 0); // Number of bits in component 1, 2, 3 & 4 respectively + writeBytes(col.getRed(), col.getGreen(), col.getBlue()); // RGB intensity } commit(chained(SEC)); this.currentColor = col; @@ -407,7 +346,7 @@ public abstract class PtocaBuilder implements PtocaConstants { assert incr >= Short.MIN_VALUE && incr <= Short.MAX_VALUE; newControlSequence(); writeShort(Math.abs(incr)); //Increment - writeByte(incr >= 0 ? 0 : 1); // Direction + writeBytes(incr >= 0 ? 0 : 1); // Direction commit(chained(SIA)); this.currentInterCharacterAdjustment = incr; diff --git a/src/java/org/apache/fop/afp/ptoca/PtocaConstants.java b/src/java/org/apache/fop/afp/ptoca/PtocaConstants.java index 2e692af2c..c53b97fd0 100644 --- a/src/java/org/apache/fop/afp/ptoca/PtocaConstants.java +++ b/src/java/org/apache/fop/afp/ptoca/PtocaConstants.java @@ -64,6 +64,6 @@ public interface PtocaConstants { byte NOP = (byte)0xF8; /** Maximum size of transparent data chunks */ - int TRANSPARENT_DATA_MAX_SIZE = 253; + int TRANSPARENT_DATA_MAX_SIZE = 253; // max length = 255 (minus the ControlSequence length) } diff --git a/src/java/org/apache/fop/afp/ptoca/TransparentDataControlSequence.java b/src/java/org/apache/fop/afp/ptoca/TransparentDataControlSequence.java new file mode 100644 index 000000000..4b4276880 --- /dev/null +++ b/src/java/org/apache/fop/afp/ptoca/TransparentDataControlSequence.java @@ -0,0 +1,89 @@ +/* + * 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.afp.ptoca; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.afp.fonts.CharactersetEncoder.EncodedChars; +import org.apache.fop.afp.ptoca.TransparentDataControlSequence.TransparentData; + +import static org.apache.fop.afp.ptoca.PtocaConstants.TRANSPARENT_DATA_MAX_SIZE; + +/** + * This object represents a series of PTOCA TransparentData (TRN) control sequences. This implements + * {@link Iterable} to enable iteration through the TRNs. + */ +final class TransparentDataControlSequence implements Iterable { + + private static final int MAX_SBCS_TRN_SIZE = TRANSPARENT_DATA_MAX_SIZE; + // The maximum size of a TRN must be an EVEN number so that we're splitting TRNs on character + // boundaries rather than in the middle of a double-byte character + private static final int MAX_DBCS_TRN_SIZE = MAX_SBCS_TRN_SIZE - 1; + + static final class TransparentData { + private final int offset; + private final int length; + private final EncodedChars encodedChars; + + private TransparentData(int offset, int length, EncodedChars encChars) { + this.offset = offset; + this.length = length; + this.encodedChars = encChars; + } + + void writeTo(OutputStream outStream) throws IOException { + encodedChars.writeTo(outStream, offset, length); + } + } + + private final List trns; + + /** + * Converts an encoded String wrapped in an {@link EncodedChars} into a series of + * {@link TransparentData} control sequences. + * + * @param encChars the encoded characters to convert to TRNs + */ + public TransparentDataControlSequence(EncodedChars encChars) { + int maxTrnLength = encChars.isDBCS() ? MAX_DBCS_TRN_SIZE : MAX_SBCS_TRN_SIZE; + int numTransData = encChars.getLength() / maxTrnLength; + int currIndex = 0; + List trns = new ArrayList(); + for (int transDataCnt = 0; transDataCnt < numTransData; transDataCnt++) { + trns.add(new TransparentData(currIndex, maxTrnLength, encChars)); + currIndex += maxTrnLength; + } + int left = encChars.getLength() - currIndex; + trns.add(new TransparentData(currIndex, left, encChars)); + this.trns = Collections.unmodifiableList(trns); + } + + /** + * The {@link Iterator} for retrieving the series of TRN control sequences. + */ + public Iterator iterator() { + return trns.iterator(); + } +} diff --git a/test/java/org/apache/fop/afp/ptoca/TransparentDataControlSequenceTestCase.java b/test/java/org/apache/fop/afp/ptoca/TransparentDataControlSequenceTestCase.java new file mode 100644 index 000000000..338c5e6f4 --- /dev/null +++ b/test/java/org/apache/fop/afp/ptoca/TransparentDataControlSequenceTestCase.java @@ -0,0 +1,73 @@ +/* + * 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.afp.ptoca; + +import java.io.IOException; +import java.io.OutputStream; + +import org.junit.Test; + +import org.apache.fop.afp.fonts.CharactersetEncoder.EncodedChars; +import org.apache.fop.afp.ptoca.TransparentDataControlSequence.TransparentData; + +import static org.apache.fop.afp.ptoca.PtocaConstants.TRANSPARENT_DATA_MAX_SIZE; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class TransparentDataControlSequenceTestCase { + + private EncodedChars encodedChars; + private final OutputStream outStream = mock(OutputStream.class); + + @Test + public void testSingleByteCharacterSet() throws IOException { + testTRNs(false); + } + + @Test + public void testDoubleByteCharacterSets() throws IOException { + testTRNs(true); + } + + public void testTRNs(boolean isDBCS) throws IOException { + for (int length = 100; length < 10000; length += 1000) { + createTRNControlSequence(isDBCS, length); + int maxTRNSize = TRANSPARENT_DATA_MAX_SIZE - (isDBCS ? 1 : 0); + int numberOfTRNs = length / maxTRNSize; + for (int i = 0; i < numberOfTRNs; i++) { + verify(encodedChars, times(1)).writeTo(outStream, i * maxTRNSize, maxTRNSize); + } + int lastOffset = numberOfTRNs * maxTRNSize; + verify(encodedChars, times(1)).writeTo(outStream, numberOfTRNs * maxTRNSize, + length - lastOffset); + } + } + + private void createTRNControlSequence(boolean isDBCS, int length) throws IOException { + encodedChars = mock(EncodedChars.class); + when(encodedChars.isDBCS()).thenReturn(isDBCS); + when(encodedChars.getLength()).thenReturn(length); + for (TransparentData trn : new TransparentDataControlSequence(encodedChars)) { + trn.writeTo(outStream); + } + } +} -- cgit v1.2.3 From 1e8a2631f0bd5c9e9f1cf889281330249ecd5b00 Mon Sep 17 00:00:00 2001 From: Mehdi Houshmand Date: Tue, 15 May 2012 09:07:02 +0000 Subject: Improved handling of AFP double-byte character sets git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1338605 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/afp/fonts/CharacterSet.java | 8 +++--- .../apache/fop/afp/fonts/CharacterSetBuilder.java | 21 ++++++++------- .../apache/fop/afp/fonts/CharactersetEncoder.java | 30 +++++++++++++--------- .../org/apache/fop/afp/fonts/FopCharacterSet.java | 4 +-- .../org/apache/fop/afp/ptoca/PtocaProducer.java | 4 +-- .../apache/fop/afp/ptoca/TextDataInfoProducer.java | 2 +- .../fop/render/afp/AFPRendererConfigurator.java | 13 +++++----- .../fop/afp/fonts/CharactersetEncoderTestCase.java | 15 ++++++----- 8 files changed, 52 insertions(+), 45 deletions(-) (limited to 'test') diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSet.java b/src/java/org/apache/fop/afp/fonts/CharacterSet.java index 341abde0b..fad5e95e6 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSet.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSet.java @@ -94,12 +94,12 @@ public class CharacterSet { * * @param codePage the code page identifier * @param encoding the encoding of the font - * @param isEBDCS if this is an EBCDIC double byte character set. + * @param charsetType the type of the characterset * @param name the character set name * @param accessor the resource accessor to load resource with * @param eventProducer for handling AFP related events */ - CharacterSet(String codePage, String encoding, boolean isEBDCS, String name, + CharacterSet(String codePage, String encoding, CharacterSetType charsetType, String name, ResourceAccessor accessor, AFPEventProducer eventProducer) { if (name.length() > MAX_NAME_LEN) { String msg = "Character set name '" + name + "' must be a maximum of " @@ -115,7 +115,7 @@ public class CharacterSet { } this.codePage = codePage; this.encoding = encoding; - this.encoder = CharactersetEncoder.newInstance(encoding, isEBDCS); + this.encoder = CharactersetEncoder.newInstance(encoding, charsetType); this.accessor = accessor; this.characterSetOrientations = new HashMap(4); @@ -306,7 +306,7 @@ public class CharacterSet { */ private CharacterSetOrientation getCharacterSetOrientation() { CharacterSetOrientation c - = (CharacterSetOrientation) characterSetOrientations.get(currentOrientation); + = characterSetOrientations.get(currentOrientation); return c; } diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java index 4988bb949..7da2d71ca 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java @@ -190,10 +190,10 @@ public abstract class CharacterSetBuilder { * @return CharacterSet object * @throws IOException if an I/O error occurs */ - public CharacterSet build(String characterSetName, String codePageName, String encoding, + public CharacterSet buildSBCS(String characterSetName, String codePageName, String encoding, ResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException { - return processFont(characterSetName, codePageName, encoding, false, accessor, - eventProducer); + return processFont(characterSetName, codePageName, encoding, CharacterSetType.SINGLE_BYTE, + accessor, eventProducer); } /** @@ -204,16 +204,16 @@ public abstract class CharacterSetBuilder { * @param characterSetName name of the characterset * @param codePageName name of the code page file * @param encoding encoding name - * @param isEDBCS if this is an EBCDIC double byte character set (DBCS) + * @param charsetType the characterset type * @param accessor used to load codepage and characterset * @param eventProducer for handling AFP related events * @return CharacterSet object * @throws IOException if an I/O error occurs */ public CharacterSet buildDBCS(String characterSetName, String codePageName, String encoding, - boolean isEDBCS, ResourceAccessor accessor, AFPEventProducer eventProducer) + CharacterSetType charsetType, ResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException { - return processFont(characterSetName, codePageName, encoding, isEDBCS, accessor, + return processFont(characterSetName, codePageName, encoding, charsetType, accessor, eventProducer); } @@ -236,7 +236,7 @@ public abstract class CharacterSetBuilder { } private CharacterSet processFont(String characterSetName, String codePageName, String encoding, - boolean isEDBCS, ResourceAccessor accessor, AFPEventProducer eventProducer) + CharacterSetType charsetType, ResourceAccessor accessor, AFPEventProducer eventProducer) throws IOException { // check for cached version of the characterset String descriptor = characterSetName + "_" + encoding + "_" + codePageName; @@ -247,7 +247,7 @@ public abstract class CharacterSetBuilder { } // characterset not in the cache, so recreating - characterSet = new CharacterSet(codePageName, encoding, isEDBCS, characterSetName, + characterSet = new CharacterSet(codePageName, encoding, charsetType, characterSetName, accessor, eventProducer); InputStream inputStream = null; @@ -465,8 +465,7 @@ public abstract class CharacterSetBuilder { } } - return (CharacterSetOrientation[]) orientations - .toArray(EMPTY_CSO_ARRAY); + return orientations.toArray(EMPTY_CSO_ARRAY); } /** @@ -570,7 +569,7 @@ public abstract class CharacterSetBuilder { String gcgiString = new String(gcgid, AFPConstants.EBCIDIC_ENCODING); - String idx = (String) codepage.get(gcgiString); + String idx = codepage.get(gcgiString); if (idx != null) { diff --git a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java index 6d85c0f52..f101bdab4 100644 --- a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java +++ b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java @@ -82,13 +82,12 @@ public abstract class CharactersetEncoder { * * @param chars the character sequence * @param encoding the encoding type - * @param isEDBCS if this encoding represents a double-byte character set * @return encoded data * @throws CharacterCodingException if encoding fails */ - public static EncodedChars encodeSBCS(CharSequence chars, String encoding, boolean isEDBCS) + public static EncodedChars encodeSBCS(CharSequence chars, String encoding) throws CharacterCodingException { - CharactersetEncoder encoder = newInstance(encoding, isEDBCS); + CharactersetEncoder encoder = newInstance(encoding, CharacterSetType.SINGLE_BYTE); return encoder.encode(chars); } @@ -98,8 +97,8 @@ public abstract class CharactersetEncoder { * sequence it will return its EBCDIC code-point, however, the "Shift In - Shift Out" operators * are removed from the sequence of bytes. These are only used in Line Data. */ - private static final class EbcdicDoubleByteEncoder extends CharactersetEncoder { - private EbcdicDoubleByteEncoder(String encoding) { + private static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder { + private EbcdicDoubleByteLineDataEncoder(String encoding) { super(encoding); } @Override @@ -117,13 +116,16 @@ public abstract class CharactersetEncoder { * byte character sets (DBCS). */ private static final class DefaultEncoder extends CharactersetEncoder { - private DefaultEncoder(String encoding) { + private final boolean isDBCS; + + private DefaultEncoder(String encoding, boolean isDBCS) { super(encoding); + this.isDBCS = isDBCS; } @Override EncodedChars getEncodedChars(byte[] byteArray, int length) { - return new EncodedChars(byteArray, false); + return new EncodedChars(byteArray, isDBCS); } } @@ -134,17 +136,21 @@ public abstract class CharactersetEncoder { * @param isEbcdicDBCS whether or not this wraps a double-byte EBCDIC code page. * @return the CharactersetEncoder */ - static CharactersetEncoder newInstance(String encoding, boolean isEbcdicDBCS) { - if (isEbcdicDBCS) { - return new EbcdicDoubleByteEncoder(encoding); - } else { - return new DefaultEncoder(encoding); + static CharactersetEncoder newInstance(String encoding, CharacterSetType charsetType) { + switch (charsetType) { + case DOUBLE_BYTE_LINE_DATA: + return new EbcdicDoubleByteLineDataEncoder(encoding); + case DOUBLE_BYTE: + return new DefaultEncoder(encoding, true); + default: + return new DefaultEncoder(encoding, false); } } /** * A container for encoded character bytes */ + // CSOFF: FinalClass - disabling "final" modifier so that this class can be mocked public static class EncodedChars { private final byte[] bytes; diff --git a/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java b/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java index f949976ba..f83c38621 100644 --- a/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java +++ b/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java @@ -42,7 +42,8 @@ public class FopCharacterSet extends CharacterSet { */ public FopCharacterSet(String codePage, String encoding, String name, Typeface charSet, AFPEventProducer eventProducer) { - super(codePage, encoding, false, name, (ResourceAccessor) null, eventProducer); + super(codePage, encoding, CharacterSetType.SINGLE_BYTE, name, (ResourceAccessor) null, + eventProducer); this.charSet = charSet; } @@ -132,5 +133,4 @@ public class FopCharacterSet extends CharacterSet { public char mapChar(char c) { return charSet.mapChar(c); } - } diff --git a/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java b/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java index 9b6d97dec..5f29bef96 100644 --- a/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java +++ b/src/java/org/apache/fop/afp/ptoca/PtocaProducer.java @@ -22,8 +22,8 @@ package org.apache.fop.afp.ptoca; import java.io.IOException; /** - * Producer interface that is passed to a {@link PresentationTextObject} to produce PTOCA control - * sequences using a {@link PtocaBuilder}. + * Producer interface that is passed to a {@link org.apache.fop.afp.modca.PresentationTextObject} + * to produce PTOCA control sequences using a {@link PtocaBuilder}. */ public interface PtocaProducer { diff --git a/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java b/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java index f7ed5a85c..4af21b12b 100644 --- a/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java +++ b/src/java/org/apache/fop/afp/ptoca/TextDataInfoProducer.java @@ -56,7 +56,7 @@ public class TextDataInfoProducer implements PtocaProducer, PtocaConstants { // Add transparent data String textString = textDataInfo.getString(); String encoding = textDataInfo.getEncoding(); - builder.addTransparentData(CharactersetEncoder.encodeSBCS(textString, encoding, false)); + builder.addTransparentData(CharactersetEncoder.encodeSBCS(textString, encoding)); } } diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index bf7fbde4a..36cdbd077 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -37,6 +37,7 @@ import org.apache.fop.afp.fonts.AFPFontCollection; import org.apache.fop.afp.fonts.AFPFontInfo; import org.apache.fop.afp.fonts.CharacterSet; import org.apache.fop.afp.fonts.CharacterSetBuilder; +import org.apache.fop.afp.fonts.CharacterSetType; import org.apache.fop.afp.fonts.DoubleByteFont; import org.apache.fop.afp.fonts.OutlineFont; import org.apache.fop.afp.fonts.RasterFont; @@ -220,7 +221,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator } } else { font.addCharacterSet(sizeMpt, CharacterSetBuilder.getSingleByteInstance() - .build(characterset, codepage, encoding, accessor, eventProducer)); + .buildSBCS(characterset, codepage, encoding, accessor, eventProducer)); } } return font; @@ -254,7 +255,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator log.error(msg); } } else { - characterSet = CharacterSetBuilder.getSingleByteInstance().build( + characterSet = CharacterSetBuilder.getSingleByteInstance().buildSBCS( characterset, codepage, encoding, accessor, eventProducer); } // Return new font object @@ -269,10 +270,10 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator } String name = afpFontCfg.getAttribute("name", characterset); CharacterSet characterSet = null; - boolean ebcdicDBCS = afpFontCfg.getAttributeAsBoolean("ebcdic-dbcs", false); - + CharacterSetType charsetType = afpFontCfg.getAttributeAsBoolean("ebcdic-dbcs", false) + ? CharacterSetType.DOUBLE_BYTE_LINE_DATA : CharacterSetType.DOUBLE_BYTE; characterSet = CharacterSetBuilder.getDoubleByteInstance().buildDBCS(characterset, - codepage, encoding, ebcdicDBCS, accessor, eventProducer); + codepage, encoding, charsetType, accessor, eventProducer); // Create a new font object DoubleByteFont font = new DoubleByteFont(name, characterSet); @@ -322,7 +323,7 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator } List fontTriplets = afi.getFontTriplets(); for (int j = 0; j < fontTriplets.size(); ++j) { - FontTriplet triplet = (FontTriplet) fontTriplets.get(j); + FontTriplet triplet = fontTriplets.get(j); if (log.isDebugEnabled()) { log.debug(" Font triplet " + triplet.getName() + ", " diff --git a/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTestCase.java b/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTestCase.java index dd776e41c..6d0daa2be 100644 --- a/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTestCase.java +++ b/test/java/org/apache/fop/afp/fonts/CharactersetEncoderTestCase.java @@ -19,10 +19,6 @@ package org.apache.fop.afp.fonts; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.CharacterCodingException; @@ -30,6 +26,10 @@ import java.nio.charset.CharacterCodingException; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Test {@link CharactersetEncoder} */ @@ -39,8 +39,9 @@ public class CharactersetEncoderTestCase { @Before public void setUp() { - singlebyteEncoder = CharactersetEncoder.newInstance("cp500", false); - doublebyteEncoder = CharactersetEncoder.newInstance("cp937", true); + singlebyteEncoder = CharactersetEncoder.newInstance("cp500", CharacterSetType.SINGLE_BYTE); + doublebyteEncoder = CharactersetEncoder.newInstance("cp937", + CharacterSetType.DOUBLE_BYTE_LINE_DATA); } // This is just an arbitrary CJK string @@ -95,7 +96,7 @@ public class CharactersetEncoderTestCase { @Test public void testEncode() throws CharacterCodingException, IOException { - CharactersetEncoder.EncodedChars encChars;// = doublebyteEncoder.encode(testCJKText); + CharactersetEncoder.EncodedChars encChars; // = doublebyteEncoder.encode(testCJKText); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); // JAVA 1.5 has a bug in the JVM in which these err for some reason... JAVA 1.6 no issues /*encChars.writeTo(bOut, 0, encChars.getLength()); -- cgit v1.2.3 From c251ff4844177a7f2e0d77a55625acfb758f343f Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Thu, 17 May 2012 01:22:08 +0000 Subject: Bugzilla #53248: Fix exception thrown from use of -print option in CLI. Submitted by Luis Bernardo. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1339441 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/cli/CommandLineOptions.java | 2 +- status.xml | 3 ++ .../apache/fop/cli/CommandLineOptionsTestCase.java | 52 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java (limited to 'test') diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index bfcdb163e..08c4cfb68 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -588,7 +588,7 @@ public class CommandLineOptions { private int parsePrintOutputOption(String[] args, int i) throws FOPException { setOutputMode(MimeConstants.MIME_FOP_PRINT); - if ((i + 1 <= args.length) + if ((i + 1 < args.length) && (args[i + 1].charAt(0) != '-')) { String arg = args[i + 1]; String[] parts = arg.split(","); diff --git a/status.xml b/status.xml index 45ca2f352..5a5c2b2dd 100644 --- a/status.xml +++ b/status.xml @@ -63,6 +63,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Fix exception thrown from use of -print option in CLI. + Fix renderer mime type for PCL output; should be application/x-pcl. diff --git a/test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java b/test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java new file mode 100644 index 000000000..5babab045 --- /dev/null +++ b/test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java @@ -0,0 +1,52 @@ +/* + * 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: CommandLineOptions.java 1293736 2012-02-26 02:29:01Z gadams $ */ + +package org.apache.fop.cli; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.apache.fop.apps.FOPException; +import org.junit.Before; +import org.junit.Test; + +public class CommandLineOptionsTestCase { + + private final CommandLineOptions clo = new CommandLineOptions(); + private final String commandLine = "-fo examples/fo/basic/simple.fo -print"; + private String[] cmd; + private boolean parsed; + + @Before + public void setUp() throws Exception { + cmd = commandLine.split(" "); + parsed = clo.parse(cmd); + } + + @Test + public void testParse() { + assertTrue(parsed); + } + + @Test + public void testGetOutputFormat() throws FOPException { + assertEquals(clo.getOutputFormat(), "application/X-fop-print"); + } + +} -- cgit v1.2.3 From 5a0e10ae9de3fdac3f68f909fce6fddea524a8d5 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Thu, 17 May 2012 01:42:56 +0000 Subject: Bugzilla #53242: Support fractional line widths in AFP renderer, fixing problem with SVG line drawing. Submitted by Luis Bernardo. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1339442 13f79535-47bb-0310-9956-ffa450edef68 --- conf/fop.xconf | 1 + .../content/xdocs/trunk/configuration.xml | 4 ++ src/documentation/content/xdocs/trunk/output.xml | 8 +++ src/java/org/apache/fop/afp/AFPConstants.java | 11 ++++ src/java/org/apache/fop/afp/AFPGraphics2D.java | 22 ++----- src/java/org/apache/fop/afp/AFPPaintingState.java | 26 ++++++++ .../afp/goca/GraphicsSetFractionalLineWidth.java | 69 ++++++++++++++++++++++ .../apache/fop/afp/goca/GraphicsSetLineWidth.java | 4 +- .../org/apache/fop/afp/modca/GraphicsObject.java | 17 +++++- .../org/apache/fop/render/afp/AFPCustomizable.java | 7 +++ .../apache/fop/render/afp/AFPDocumentHandler.java | 5 ++ .../fop/render/afp/AFPRendererConfigurator.java | 8 +++ status.xml | 3 + .../org/apache/fop/afp/AFPGraphics2DTestCase.java | 57 ++++++++++++++++++ .../GraphicsSetFractionalLineWidthTestCase.java | 59 ++++++++++++++++++ .../fop/afp/goca/GraphicsSetLineWidthTestCase.java | 57 ++++++++++++++++++ 16 files changed, 336 insertions(+), 22 deletions(-) create mode 100644 src/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidth.java create mode 100644 test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java create mode 100644 test/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidthTestCase.java create mode 100644 test/java/org/apache/fop/afp/goca/GraphicsSetLineWidthTestCase.java (limited to 'test') diff --git a/conf/fop.xconf b/conf/fop.xconf index 10b31cf86..01f12fd14 100644 --- a/conf/fop.xconf +++ b/conf/fop.xconf @@ -94,6 +94,7 @@ the location of this file. --> 240 + 2.5 resources.afp diff --git a/src/documentation/content/xdocs/trunk/configuration.xml b/src/documentation/content/xdocs/trunk/configuration.xml index c56b974f8..b30a091a5 100644 --- a/src/documentation/content/xdocs/trunk/configuration.xml +++ b/src/documentation/content/xdocs/trunk/configuration.xml @@ -471,6 +471,7 @@ 240 + 2.5 resources.afp @@ -482,6 +483,9 @@

The default value for the "renderer-resolution" is 240 dpi.

+

+ The default line width is device dependent and may need to be fine tuned so that the output matches the expected result. The default correction value is 2.5. +

+ + Support fractional line widths in AFP renderer, fixing problem with SVG line drawing. + Fix exception thrown from use of -print option in CLI. diff --git a/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java b/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java new file mode 100644 index 000000000..7b261d482 --- /dev/null +++ b/test/java/org/apache/fop/afp/AFPGraphics2DTestCase.java @@ -0,0 +1,57 @@ +/* + * 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.afp; + +import java.awt.BasicStroke; + +import org.junit.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.fop.afp.modca.GraphicsObject; +import org.apache.fop.fonts.FontInfo; + +public class AFPGraphics2DTestCase { + + private final float lineWidth = 1.0f; + private final float correction = 2.5f; + private final BasicStroke stroke = mock(BasicStroke.class); + private final GraphicsObject gObject = mock(GraphicsObject.class); + private final AFPPaintingState paintingState = mock(AFPPaintingState.class); + private final AFPResourceManager resourceManager = mock(AFPResourceManager.class); + private final AFPResourceInfo resourceInfo = mock(AFPResourceInfo.class); + private final FontInfo fontInfo = mock(FontInfo.class); + private AFPGraphics2D graphics2D = new AFPGraphics2D(false, paintingState, resourceManager, resourceInfo, + fontInfo); + + @Test + public void testApplyStroke() { + // note: this only tests the setLineWidth in the GraphicsObject + float correctedLineWidth = lineWidth * correction; + when(stroke.getLineWidth()).thenReturn(lineWidth); + when(paintingState.getLineWidthCorrection()).thenReturn(correction); + graphics2D.setGraphicsObject(gObject); + graphics2D.applyStroke(stroke); + verify(gObject).setLineWidth(correctedLineWidth); + } + +} diff --git a/test/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidthTestCase.java b/test/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidthTestCase.java new file mode 100644 index 000000000..f34275de0 --- /dev/null +++ b/test/java/org/apache/fop/afp/goca/GraphicsSetFractionalLineWidthTestCase.java @@ -0,0 +1,59 @@ +/* + * 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.afp.goca; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class GraphicsSetFractionalLineWidthTestCase { + + private final float multiplier = 5.25f; + private final GraphicsSetFractionalLineWidth gsflw = new GraphicsSetFractionalLineWidth(multiplier); + + @Test + public void testGetDataLength() { + assertEquals(4, gsflw.getDataLength()); + } + + @Test + public void testWriteToStream() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + gsflw.writeToStream(baos); + baos.close(); + // note: 0.25 = 64/256 and 64 = 4*16, so 0x40 + // expected: 0x11 (order code), 0x02 (2 bytes next), 0x05 (integral multiplier), 0x40 (fractional + // multiplier) + byte[] expected = new byte[] {0x11, 0x02, 0x05, 0x40}; + assertTrue(Arrays.equals(expected, baos.toByteArray())); + } + + @Test + public void testToString() { + // lets make sure we keep good coverage... + assertEquals("GraphicsSetFractionalLineWidth{multiplier=" + multiplier + "}", gsflw.toString()); + } + +} diff --git a/test/java/org/apache/fop/afp/goca/GraphicsSetLineWidthTestCase.java b/test/java/org/apache/fop/afp/goca/GraphicsSetLineWidthTestCase.java new file mode 100644 index 000000000..c0a18a551 --- /dev/null +++ b/test/java/org/apache/fop/afp/goca/GraphicsSetLineWidthTestCase.java @@ -0,0 +1,57 @@ +/* + * 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.afp.goca; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class GraphicsSetLineWidthTestCase { + + private final int multiplier = 5; + private final GraphicsSetLineWidth gslw = new GraphicsSetLineWidth(multiplier); + + @Test + public void testGetDataLength() { + assertEquals(2, gslw.getDataLength()); + } + + @Test + public void testWriteToStream() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + gslw.writeToStream(baos); + baos.close(); + // expected: 0x19 (order code), 0x05 (integral multiplier) + byte[] expected = new byte[] {0x19, 0x05}; + assertTrue(Arrays.equals(expected, baos.toByteArray())); + } + + @Test + public void testToString() { + // lets make sure we keep good coverage... + assertEquals("GraphicsSetLineWidth{multiplier=" + multiplier + "}", gslw.toString()); + } + +} -- cgit v1.2.3 From 3f7239142b1221de3b7b2ce7f5ca32ce03f67a14 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Tue, 22 May 2012 18:26:15 +0000 Subject: Bugzilla #52144: Fix crash on use of version switch (-v). Submitted by Luis Bernardo. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1341585 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/cli/CommandLineOptions.java | 5 ++++- status.xml | 3 +++ .../apache/fop/cli/CommandLineOptionsTestCase.java | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index 08c4cfb68..7d5752d6d 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -357,8 +357,11 @@ public class CommandLineOptions { } else if (args[i].equals("-a")) { this.renderingOptions.put(Accessibility.ACCESSIBILITY, Boolean.TRUE); } else if (args[i].equals("-v")) { - /* Currently just print the version */ + /* verbose mode although users may expect version; currently just print the version */ printVersion(); + if (args.length == 1) { + return false; + } } else if (args[i].equals("-param")) { if (i + 2 < args.length) { String name = args[++i]; diff --git a/status.xml b/status.xml index 9b63c1d73..73ad014cf 100644 --- a/status.xml +++ b/status.xml @@ -63,6 +63,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Fix crash on use of version switch (-v). + Support fractional line widths in AFP renderer, fixing problem with SVG line drawing. diff --git a/test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java b/test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java index 5babab045..9a80fd964 100644 --- a/test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java +++ b/test/java/org/apache/fop/cli/CommandLineOptionsTestCase.java @@ -22,6 +22,8 @@ package org.apache.fop.cli; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.IOException; + import org.apache.fop.apps.FOPException; import org.junit.Before; import org.junit.Test; @@ -49,4 +51,22 @@ public class CommandLineOptionsTestCase { assertEquals(clo.getOutputFormat(), "application/X-fop-print"); } + @Test + public void testVandVersionSwitchs() throws FOPException, IOException { + // test -v + String cl1 = "-v"; + String[] cmd1 = cl1.split(" "); + CommandLineOptions clo1 = new CommandLineOptions(); + assertTrue(!clo1.parse(cmd1)); + // test -version + String cl2 = "-version"; + String[] cmd2 = cl2.split(" "); + CommandLineOptions clo2 = new CommandLineOptions(); + assertTrue(!clo2.parse(cmd2)); + // test -v + more switches + String cl3 = "-v " + commandLine; + String[] cmd3 = cl3.split(" "); + CommandLineOptions clo3 = new CommandLineOptions(); + assertTrue(clo3.parse(cmd3)); + } } -- cgit v1.2.3 From 89b98e43e014d7045a548b7f88be265c2621a328 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 25 May 2012 15:15:28 +0000 Subject: Added support for the role property on fo:page-sequence, fo:flow and fo:static-content. This allows to change the mapping of those FOs to PDF structure types when enabling accessibility. Suggested by Martin Koegler as part of Bugzilla #50852 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1342680 13f79535-47bb-0310-9956-ffa450edef68 --- .../DummyStructureTreeEventHandler.java | 2 +- .../StructureTree2SAXEventAdapter.java | 10 +++- .../accessibility/StructureTreeEventHandler.java | 3 +- .../fo/StructureTreeEventTrigger.java | 3 +- .../fop/fo/pagination/AbstractPageSequence.java | 15 +++-- src/java/org/apache/fop/fo/pagination/Flow.java | 14 ++++- .../apache/fop/render/intermediate/IFParser.java | 12 +++- .../intermediate/IFStructureTreeBuilder.java | 4 +- .../org/apache/fop/render/pdf/FOToPDFRoleMap.java | 49 ++++++++-------- .../fop/render/pdf/PDFLogicalStructureHandler.java | 21 +------ .../fop/render/pdf/PDFStructureTreeBuilder.java | 67 ++++++++++++++-------- status.xml | 5 ++ .../IFStructureTreeBuilderTestCase.java | 6 +- test/pdf/accessibility/role.fo | 13 +++-- 14 files changed, 132 insertions(+), 92 deletions(-) (limited to 'test') diff --git a/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java b/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java index 66eaece89..c63c721e5 100644 --- a/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java +++ b/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java @@ -34,7 +34,7 @@ public final class DummyStructureTreeEventHandler implements StructureTreeEventH private DummyStructureTreeEventHandler() { } /** {@inheritDoc} */ - public void startPageSequence(Locale locale) { + public void startPageSequence(Locale locale, String role) { } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java b/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java index 79c589f9b..7a375ef20 100644 --- a/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java +++ b/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java @@ -30,6 +30,7 @@ import org.apache.fop.fo.FOElementMapping; import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.fo.extensions.InternalElementMapping; import org.apache.fop.render.intermediate.IFConstants; +import org.apache.fop.util.XMLConstants; /** * Converts structure tree events to SAX events. @@ -52,16 +53,19 @@ public final class StructureTree2SAXEventAdapter implements StructureTreeEventHa } /** {@inheritDoc} */ - public void startPageSequence(Locale locale) { + public void startPageSequence(Locale locale, String role) { try { - + AttributesImpl attributes = new AttributesImpl(); + if (role != null) { + attributes.addAttribute("", "type", "type", XMLConstants.CDATA, role); + } contentHandler.startPrefixMapping( InternalElementMapping.STANDARD_PREFIX, InternalElementMapping.URI); contentHandler.startPrefixMapping( ExtensionElementMapping.STANDARD_PREFIX, ExtensionElementMapping.URI); contentHandler.startElement(IFConstants.NAMESPACE, IFConstants.EL_STRUCTURE_TREE, IFConstants.EL_STRUCTURE_TREE, - new AttributesImpl()); + attributes); } catch (SAXException e) { throw new RuntimeException(e); } diff --git a/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java b/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java index 4b94d61f1..46b724626 100644 --- a/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java +++ b/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java @@ -34,8 +34,9 @@ public interface StructureTreeEventHandler { * Starts a page sequence structure tree node. * * @param locale The locale of the page sequence + * @param role the value of the role property. May be null. */ - void startPageSequence(Locale locale); + void startPageSequence(Locale locale, String role); /** * Starts a structure tree node. diff --git a/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java b/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java index 957f40870..51f7f2bed 100644 --- a/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java +++ b/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java @@ -89,7 +89,8 @@ class StructureTreeEventTrigger extends FOEventHandler { locale = new Locale(pageSeq.getLanguage()); } } - structureTreeEventHandler.startPageSequence(locale); + String role = pageSeq.getCommonAccessibility().getRole(); + structureTreeEventHandler.startPageSequence(locale, role); } @Override diff --git a/src/java/org/apache/fop/fo/pagination/AbstractPageSequence.java b/src/java/org/apache/fop/fo/pagination/AbstractPageSequence.java index 8640ab19b..d1ccf7273 100644 --- a/src/java/org/apache/fop/fo/pagination/AbstractPageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/AbstractPageSequence.java @@ -24,6 +24,8 @@ import org.apache.fop.datatypes.Numeric; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.properties.CommonAccessibility; +import org.apache.fop.fo.properties.CommonAccessibilityHolder; /** * Abstract base class for the @@ -31,9 +33,8 @@ import org.apache.fop.fo.PropertyList; * * fox:external-document extension object. */ -public abstract class AbstractPageSequence extends FObj { +public abstract class AbstractPageSequence extends FObj implements CommonAccessibilityHolder { - // The value of properties relevant for fo:page-sequence. /** initial page number */ protected Numeric initialPageNumber; /** forced page count */ @@ -42,11 +43,12 @@ public abstract class AbstractPageSequence extends FObj { private int letterValue; private char groupingSeparator; private int groupingSize; - private Numeric referenceOrientation; //XSL 1.1 + private Numeric referenceOrientation; private String language; private String country; private String numberConversionFeatures; - // End of property values + + private CommonAccessibility commonAccessibility; private PageNumberGenerator pageNumberGenerator; @@ -76,6 +78,7 @@ public abstract class AbstractPageSequence extends FObj { language = pList.get(PR_LANGUAGE).getString(); country = pList.get(PR_COUNTRY).getString(); numberConversionFeatures = pList.get(PR_X_NUMBER_CONVERSION_FEATURES).getString(); + commonAccessibility = CommonAccessibility.getInstance(pList); } /** {@inheritDoc} */ @@ -130,6 +133,10 @@ public abstract class AbstractPageSequence extends FObj { return pageNumberGenerator.makeFormattedPageNumber(pageNumber); } + public CommonAccessibility getCommonAccessibility() { + return commonAccessibility; + } + /** * Public accessor for the ancestor Root. * @return the ancestor Root diff --git a/src/java/org/apache/fop/fo/pagination/Flow.java b/src/java/org/apache/fop/fo/pagination/Flow.java index 153f06fc1..981485e32 100644 --- a/src/java/org/apache/fop/fo/pagination/Flow.java +++ b/src/java/org/apache/fop/fo/pagination/Flow.java @@ -26,16 +26,19 @@ import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.properties.CommonAccessibility; +import org.apache.fop.fo.properties.CommonAccessibilityHolder; /** * Class modelling the * fo:flow object. * */ -public class Flow extends FObj { - // The value of properties relevant for fo:flow. +public class Flow extends FObj implements CommonAccessibilityHolder { + private String flowName; - // End of property values + + private CommonAccessibility commonAccessibility; /** used for FO validation */ private boolean blockItemFound = false; @@ -52,6 +55,7 @@ public class Flow extends FObj { public void bind(PropertyList pList) throws FOPException { super.bind(pList); flowName = pList.get(PR_FLOW_NAME).getString(); + commonAccessibility = CommonAccessibility.getInstance(pList); } /** {@inheritDoc} */ @@ -120,6 +124,10 @@ public class Flow extends FObj { return flowName; } + public CommonAccessibility getCommonAccessibility() { + return commonAccessibility; + } + /** {@inheritDoc} */ public String getLocalName() { return "flow"; diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java index 33e6931de..827eec820 100644 --- a/src/java/org/apache/fop/render/intermediate/IFParser.java +++ b/src/java/org/apache/fop/render/intermediate/IFParser.java @@ -156,7 +156,7 @@ public class IFParser implements IFConstants { private ContentHandler navParser; - private ContentHandler structureTreeHandler; + private StructureTreeHandler structureTreeHandler; private Attributes pageSequenceAttributes; @@ -165,12 +165,18 @@ public class IFParser implements IFConstants { private final class StructureTreeHandler extends DefaultHandler { + private final Locale pageSequenceLanguage; + private final StructureTreeEventHandler structureTreeEventHandler; private StructureTreeHandler(StructureTreeEventHandler structureTreeEventHandler, Locale pageSequenceLanguage) throws SAXException { + this.pageSequenceLanguage = pageSequenceLanguage; this.structureTreeEventHandler = structureTreeEventHandler; - structureTreeEventHandler.startPageSequence(pageSequenceLanguage); + } + + void startStructureTree(String type) { + structureTreeEventHandler.startPageSequence(pageSequenceLanguage, type); } public void endDocument() throws SAXException { @@ -263,6 +269,8 @@ public class IFParser implements IFConstants { } else if (localName.equals(EL_STRUCTURE_TREE)) { if (userAgent.isAccessibilityEnabled()) { + String type = attributes.getValue("type"); + structureTreeHandler.startStructureTree(type); delegate = structureTreeHandler; } else { /* Delegate to a handler that does nothing */ diff --git a/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java b/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java index 3d9885914..9ba9afd81 100644 --- a/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java +++ b/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java @@ -189,11 +189,11 @@ final class IFStructureTreeBuilder implements StructureTreeEventHandler { pageSequenceEventRecorders.get(pageSequenceIndex).replay(handler); } - public void startPageSequence(Locale locale) { + public void startPageSequence(Locale locale, String role) { SAXEventRecorder eventRecorder = new SAXEventRecorder(); pageSequenceEventRecorders.add(eventRecorder); delegate = StructureTree2SAXEventAdapter.newInstance(eventRecorder); - delegate.startPageSequence(locale); + delegate.startPageSequence(locale, role); } public void endPageSequence() { diff --git a/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java b/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java index 9b76d0620..0f752e886 100644 --- a/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java +++ b/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java @@ -103,9 +103,9 @@ final class FOToPDFRoleMap { addStructureType("Formula"); addStructureType("Form"); - NON_STRUCT = (PDFName) STANDARD_STRUCTURE_TYPES.get("NonStruct"); + NON_STRUCT = STANDARD_STRUCTURE_TYPES.get("NonStruct"); assert NON_STRUCT != null; - THEAD = (PDFName) STANDARD_STRUCTURE_TYPES.get("THead"); + THEAD = STANDARD_STRUCTURE_TYPES.get("THead"); assert THEAD != null; // Create the standard mappings @@ -155,7 +155,7 @@ final class FOToPDFRoleMap { } private static void addMapping(String fo, String structureType) { - PDFName type = (PDFName) STANDARD_STRUCTURE_TYPES.get(structureType); + PDFName type = STANDARD_STRUCTURE_TYPES.get(structureType); assert type != null; addMapping(fo, new SimpleMapper(type)); } @@ -165,21 +165,6 @@ final class FOToPDFRoleMap { } - /** - * Maps a Formatting Object to a PDFName representing the associated structure type. - * @param fo the formatting object's local name - * @param parent the parent of the structure element to be mapped - * @return the structure type or null if no match could be found - */ - public static PDFName mapFormattingObject(String fo, PDFObject parent) { - Mapper mapper = (Mapper) DEFAULT_MAPPINGS.get(fo); - if (mapper != null) { - return mapper.getStructureType(parent); - } else { - return NON_STRUCT; - } - } - /** * Maps a Formatting Object to a PDFName representing the associated structure type. * @param fo the formatting object's local name @@ -192,11 +177,11 @@ final class FOToPDFRoleMap { PDFObject parent, EventBroadcaster eventBroadcaster) { PDFName type = null; if (role == null) { - type = mapFormattingObject(fo, parent); + type = getDefaultMappingFor(fo, parent); } else { - type = (PDFName) STANDARD_STRUCTURE_TYPES.get(role); + type = STANDARD_STRUCTURE_TYPES.get(role); if (type == null) { - type = mapFormattingObject(fo, parent); + type = getDefaultMappingFor(fo, parent); PDFEventProducer.Provider.get(eventBroadcaster).nonStandardStructureType(fo, fo, role, type.toString().substring(1)); } @@ -205,6 +190,21 @@ final class FOToPDFRoleMap { return type; } + /** + * Maps a Formatting Object to a PDFName representing the associated structure type. + * @param fo the formatting object's local name + * @param parent the parent of the structure element to be mapped + * @return the structure type or NonStruct if no match could be found + */ + private static PDFName getDefaultMappingFor(String fo, PDFObject parent) { + Mapper mapper = DEFAULT_MAPPINGS.get(fo); + if (mapper != null) { + return mapper.getStructureType(parent); + } else { + return NON_STRUCT; + } + } + private interface Mapper { PDFName getStructureType(PDFObject parent); } @@ -226,14 +226,13 @@ final class FOToPDFRoleMap { private static class TableCellMapper implements Mapper { public PDFName getStructureType(PDFObject parent) { - PDFStructElem grandParent = (PDFStructElem) - ((PDFStructElem) parent).getParentStructElem(); + PDFStructElem grandParent = ((PDFStructElem) parent).getParentStructElem(); //TODO What to do with cells from table-footer? Currently they are mapped on TD. PDFName type; if (THEAD.equals(grandParent.getStructureType())) { - type = (PDFName) STANDARD_STRUCTURE_TYPES.get("TH"); + type = STANDARD_STRUCTURE_TYPES.get("TH"); } else { - type = (PDFName) STANDARD_STRUCTURE_TYPES.get("TD"); + type = STANDARD_STRUCTURE_TYPES.get("TD"); } assert type != null; return type; diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java index 1c9f9b49d..6559e8d56 100644 --- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java @@ -19,8 +19,6 @@ package org.apache.fop.render.pdf; -import java.util.Locale; - import org.apache.fop.pdf.PDFArray; import org.apache.fop.pdf.PDFDictionary; import org.apache.fop.pdf.PDFDocument; @@ -29,7 +27,6 @@ import org.apache.fop.pdf.PDFName; import org.apache.fop.pdf.PDFPage; import org.apache.fop.pdf.PDFParentTree; import org.apache.fop.pdf.PDFStructElem; -import org.apache.fop.pdf.PDFStructTreeRoot; /** @@ -59,8 +56,6 @@ class PDFLogicalStructureHandler { */ private PDFArray pageParentTreeArray; - private PDFStructElem rootStructureElement; - /** * Class providing the necessary information for bracketing content * associated to a structure element as a marked-content sequence. @@ -95,22 +90,10 @@ class PDFLogicalStructureHandler { */ PDFLogicalStructureHandler(PDFDocument pdfDoc) { this.pdfDoc = pdfDoc; - PDFStructTreeRoot structTreeRoot = pdfDoc.makeStructTreeRoot(parentTree); - rootStructureElement = pdfDoc.makeStructureElement( - FOToPDFRoleMap.mapFormattingObject("root", structTreeRoot), structTreeRoot); - structTreeRoot.addKid(rootStructureElement); } - - PDFStructElem createPageSequence(Locale language) { - PDFStructElem structElemPart = pdfDoc.makeStructureElement( - FOToPDFRoleMap.mapFormattingObject("page-sequence", rootStructureElement), - rootStructureElement); - rootStructureElement.addKid(structElemPart); - if (language != null) { - structElemPart.setLanguage(language); - } - return structElemPart; + PDFParentTree getParentTree() { + return parentTree; } private int getNextParentTreeKey() { diff --git a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java index 2a2a4a392..3839d47bc 100644 --- a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java +++ b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java @@ -29,7 +29,11 @@ import org.apache.fop.accessibility.StructureTreeEventHandler; import org.apache.fop.events.EventBroadcaster; import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.pdf.PDFFactory; +import org.apache.fop.pdf.PDFName; +import org.apache.fop.pdf.PDFObject; +import org.apache.fop.pdf.PDFParentTree; import org.apache.fop.pdf.PDFStructElem; +import org.apache.fop.pdf.PDFStructTreeRoot; class PDFStructureTreeBuilder implements StructureTreeEventHandler { @@ -41,21 +45,42 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler { private LinkedList ancestors = new LinkedList(); + private PDFStructElem rootStructureElement; + void setPdfFactory(PDFFactory pdfFactory) { this.pdfFactory = pdfFactory; } void setLogicalStructureHandler(PDFLogicalStructureHandler logicalStructureHandler) { this.logicalStructureHandler = logicalStructureHandler; + createRootStructureElement(); + } + + private void createRootStructureElement() { + assert rootStructureElement == null; + PDFParentTree parentTree = logicalStructureHandler.getParentTree(); + PDFStructTreeRoot structTreeRoot = pdfFactory.getDocument().makeStructTreeRoot(parentTree); + rootStructureElement = createStructureElement("root", structTreeRoot, null); + structTreeRoot.addKid(rootStructureElement); } void setEventBroadcaster(EventBroadcaster eventBroadcaster) { this.eventBroadcaster = eventBroadcaster; } - public void startPageSequence(Locale locale) { + public void startPageSequence(Locale language, String role) { ancestors = new LinkedList(); - ancestors.add(logicalStructureHandler.createPageSequence(locale)); + PDFStructElem structElem = createStructureElement("page-sequence", rootStructureElement, role); + if (language != null) { + structElem.setLanguage(language); + } + rootStructureElement.addKid(structElem); + ancestors.add(structElem); + } + + private PDFStructElem createStructureElement(String name, PDFObject parent, String role) { + PDFName structureType = FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster); + return pdfFactory.getDocument().makeStructureElement(structureType, parent); } public void endPageSequence() { @@ -64,12 +89,10 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler { public StructureTreeElement startNode(String name, Attributes attributes) { PDFStructElem parent = ancestors.getFirst(); String role = attributes.getValue("role"); - PDFStructElem created; - created = pdfFactory.getDocument().makeStructureElement( - FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster), parent); - parent.addKid(created); - ancestors.addFirst(created); - return created; + PDFStructElem structElem = createStructureElement(name, parent, role); + parent.addKid(structElem); + ancestors.addFirst(structElem); + return structElem; } public void endNode(String name) { @@ -83,34 +106,30 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler { public StructureTreeElement startImageNode(String name, Attributes attributes) { PDFStructElem parent = ancestors.getFirst(); String role = attributes.getValue("role"); - PDFStructElem created; - created = pdfFactory.getDocument().makeStructureElement( - FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster), parent); - parent.addKid(created); + PDFStructElem structElem = createStructureElement(name, parent, role); + parent.addKid(structElem); String altTextNode = attributes.getValue(ExtensionElementMapping.URI, "alt-text"); if (altTextNode != null) { - created.put("Alt", altTextNode); + structElem.put("Alt", altTextNode); } else { - created.put("Alt", "No alternate text specified"); + structElem.put("Alt", "No alternate text specified"); } - ancestors.addFirst(created); - return created; + ancestors.addFirst(structElem); + return structElem; } public StructureTreeElement startReferencedNode(String name, Attributes attributes) { PDFStructElem parent = ancestors.getFirst(); String role = attributes.getValue("role"); - PDFStructElem created; + PDFStructElem structElem; if ("#PCDATA".equals(name)) { - created = new PDFStructElem.Placeholder(parent, name); + structElem = new PDFStructElem.Placeholder(parent, name); } else { - created = pdfFactory.getDocument().makeStructureElement( - FOToPDFRoleMap.mapFormattingObject(name, role, parent, - eventBroadcaster), parent); + structElem = createStructureElement(name, parent, role); } - parent.addKid(created); - ancestors.addFirst(created); - return created; + parent.addKid(structElem); + ancestors.addFirst(structElem); + return structElem; } } diff --git a/status.xml b/status.xml index f7186e095..fc5b5c630 100644 --- a/status.xml +++ b/status.xml @@ -63,6 +63,11 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Added support for the role property on fo:page-sequence, fo:flow and fo:static-content. This + allows to change the mapping of those FOs to PDF structure types when enabling + accessibility. + Stop outputting the Type entry for structure elements in order to create a smaller PDF ouptut when accessibility is enabled. diff --git a/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java b/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java index 65c6b25a6..6819fed79 100644 --- a/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java +++ b/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java @@ -61,7 +61,7 @@ public class IFStructureTreeBuilderTestCase { // Expected } - sut.startPageSequence(null); + sut.startPageSequence(null, null); sut.endPageSequence(); sut.replayEventsForPageSequence(handler, 0); @@ -89,7 +89,7 @@ public class IFStructureTreeBuilderTestCase { final String nodeName = "block"; final ContentHandler handler = mock(ContentHandler.class); - sut.startPageSequence(null); + sut.startPageSequence(null, null); sut.startNode(nodeName, createSimpleAttributes(attributes)); sut.endPageSequence(); @@ -105,7 +105,7 @@ public class IFStructureTreeBuilderTestCase { final String nodeName = "block"; final ContentHandler handler = mock(ContentHandler.class); - sut.startPageSequence(null); + sut.startPageSequence(null, null); sut.endNode(nodeName); sut.endPageSequence(); diff --git a/test/pdf/accessibility/role.fo b/test/pdf/accessibility/role.fo index ced8a4d44..885638592 100644 --- a/test/pdf/accessibility/role.fo +++ b/test/pdf/accessibility/role.fo @@ -19,12 +19,17 @@ - + page-height="240pt" page-width="320pt" margin="10pt" margin-bottom="8pt"> + + - - + + + + + Date: Fri, 25 May 2012 15:55:46 +0000 Subject: Updated reference PDFs following changes from rev. 1341992 and 1342680 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1342703 13f79535-47bb-0310-9956-ffa450edef68 --- test/pdf/1.5/test.pdf | Bin 94918 -> 92661 bytes .../pdf/background-image_jpg_repeat.pdf | Bin 12814 -> 12755 bytes .../pdf/background-image_jpg_single.pdf | Bin 12653 -> 12594 bytes .../pdf/background-image_png_repeat.pdf | Bin 35437 -> 35378 bytes .../pdf/background-image_png_single.pdf | Bin 58648 -> 58589 bytes .../pdf/background-image_svg_repeat.pdf | Bin 17056 -> 16997 bytes .../pdf/background-image_svg_single.pdf | Bin 9931 -> 9872 bytes test/pdf/accessibility/pdf/complete.pdf | Bin 97061 -> 94814 bytes test/pdf/accessibility/pdf/image_jpg.pdf | Bin 9078 -> 8999 bytes test/pdf/accessibility/pdf/image_png.pdf | Bin 58119 -> 58040 bytes test/pdf/accessibility/pdf/image_svg.pdf | Bin 14260 -> 14161 bytes test/pdf/accessibility/pdf/image_wmf.pdf | Bin 248229 -> 247758 bytes test/pdf/accessibility/pdf/leader.pdf | Bin 9379 -> 9300 bytes test/pdf/accessibility/pdf/links.pdf | Bin 9712 -> 9533 bytes test/pdf/accessibility/pdf/role.pdf | Bin 18976 -> 19023 bytes test/pdf/accessibility/pdf/role_non-standard.pdf | Bin 18990 -> 18291 bytes test/pdf/accessibility/pdf/text_1.pdf | Bin 7504 -> 7445 bytes test/pdf/accessibility/pdf/text_2.pdf | Bin 10346 -> 10247 bytes test/pdf/accessibility/pdf/text_font-embedding.pdf | Bin 19741 -> 19682 bytes 19 files changed, 0 insertions(+), 0 deletions(-) (limited to 'test') diff --git a/test/pdf/1.5/test.pdf b/test/pdf/1.5/test.pdf index 4c25c0847..6175a270f 100644 Binary files a/test/pdf/1.5/test.pdf and b/test/pdf/1.5/test.pdf differ diff --git a/test/pdf/accessibility/pdf/background-image_jpg_repeat.pdf b/test/pdf/accessibility/pdf/background-image_jpg_repeat.pdf index 9b4a7fc20..bf3cdccad 100644 Binary files a/test/pdf/accessibility/pdf/background-image_jpg_repeat.pdf and b/test/pdf/accessibility/pdf/background-image_jpg_repeat.pdf differ diff --git a/test/pdf/accessibility/pdf/background-image_jpg_single.pdf b/test/pdf/accessibility/pdf/background-image_jpg_single.pdf index d1d0ecb1b..4d40ebc7a 100644 Binary files a/test/pdf/accessibility/pdf/background-image_jpg_single.pdf and b/test/pdf/accessibility/pdf/background-image_jpg_single.pdf differ diff --git a/test/pdf/accessibility/pdf/background-image_png_repeat.pdf b/test/pdf/accessibility/pdf/background-image_png_repeat.pdf index ccb2cf089..7847bcedd 100644 Binary files a/test/pdf/accessibility/pdf/background-image_png_repeat.pdf and b/test/pdf/accessibility/pdf/background-image_png_repeat.pdf differ diff --git a/test/pdf/accessibility/pdf/background-image_png_single.pdf b/test/pdf/accessibility/pdf/background-image_png_single.pdf index 902520b95..9458b54f8 100644 Binary files a/test/pdf/accessibility/pdf/background-image_png_single.pdf and b/test/pdf/accessibility/pdf/background-image_png_single.pdf differ diff --git a/test/pdf/accessibility/pdf/background-image_svg_repeat.pdf b/test/pdf/accessibility/pdf/background-image_svg_repeat.pdf index a720a5b9a..41c2ee500 100644 Binary files a/test/pdf/accessibility/pdf/background-image_svg_repeat.pdf and b/test/pdf/accessibility/pdf/background-image_svg_repeat.pdf differ diff --git a/test/pdf/accessibility/pdf/background-image_svg_single.pdf b/test/pdf/accessibility/pdf/background-image_svg_single.pdf index 7e6e3e9d4..8c2dc1006 100644 Binary files a/test/pdf/accessibility/pdf/background-image_svg_single.pdf and b/test/pdf/accessibility/pdf/background-image_svg_single.pdf differ diff --git a/test/pdf/accessibility/pdf/complete.pdf b/test/pdf/accessibility/pdf/complete.pdf index f1dc10559..3aada8c00 100644 Binary files a/test/pdf/accessibility/pdf/complete.pdf and b/test/pdf/accessibility/pdf/complete.pdf differ diff --git a/test/pdf/accessibility/pdf/image_jpg.pdf b/test/pdf/accessibility/pdf/image_jpg.pdf index e943c83e5..21bae3826 100644 Binary files a/test/pdf/accessibility/pdf/image_jpg.pdf and b/test/pdf/accessibility/pdf/image_jpg.pdf differ diff --git a/test/pdf/accessibility/pdf/image_png.pdf b/test/pdf/accessibility/pdf/image_png.pdf index 5ea44673b..5bd99a623 100644 Binary files a/test/pdf/accessibility/pdf/image_png.pdf and b/test/pdf/accessibility/pdf/image_png.pdf differ diff --git a/test/pdf/accessibility/pdf/image_svg.pdf b/test/pdf/accessibility/pdf/image_svg.pdf index db1e061cf..a9428fd3f 100644 Binary files a/test/pdf/accessibility/pdf/image_svg.pdf and b/test/pdf/accessibility/pdf/image_svg.pdf differ diff --git a/test/pdf/accessibility/pdf/image_wmf.pdf b/test/pdf/accessibility/pdf/image_wmf.pdf index 65c46d12a..c15a05223 100644 Binary files a/test/pdf/accessibility/pdf/image_wmf.pdf and b/test/pdf/accessibility/pdf/image_wmf.pdf differ diff --git a/test/pdf/accessibility/pdf/leader.pdf b/test/pdf/accessibility/pdf/leader.pdf index d270c25a1..4b91dfe8e 100644 Binary files a/test/pdf/accessibility/pdf/leader.pdf and b/test/pdf/accessibility/pdf/leader.pdf differ diff --git a/test/pdf/accessibility/pdf/links.pdf b/test/pdf/accessibility/pdf/links.pdf index b2a5a4209..d2ff84ea4 100644 Binary files a/test/pdf/accessibility/pdf/links.pdf and b/test/pdf/accessibility/pdf/links.pdf differ diff --git a/test/pdf/accessibility/pdf/role.pdf b/test/pdf/accessibility/pdf/role.pdf index 329925bcd..38fcf1bde 100644 Binary files a/test/pdf/accessibility/pdf/role.pdf and b/test/pdf/accessibility/pdf/role.pdf differ diff --git a/test/pdf/accessibility/pdf/role_non-standard.pdf b/test/pdf/accessibility/pdf/role_non-standard.pdf index 84daea788..6f1edea19 100644 Binary files a/test/pdf/accessibility/pdf/role_non-standard.pdf and b/test/pdf/accessibility/pdf/role_non-standard.pdf differ diff --git a/test/pdf/accessibility/pdf/text_1.pdf b/test/pdf/accessibility/pdf/text_1.pdf index 13f01711d..bacd7a9d0 100644 Binary files a/test/pdf/accessibility/pdf/text_1.pdf and b/test/pdf/accessibility/pdf/text_1.pdf differ diff --git a/test/pdf/accessibility/pdf/text_2.pdf b/test/pdf/accessibility/pdf/text_2.pdf index 943263994..0283764cd 100644 Binary files a/test/pdf/accessibility/pdf/text_2.pdf and b/test/pdf/accessibility/pdf/text_2.pdf differ diff --git a/test/pdf/accessibility/pdf/text_font-embedding.pdf b/test/pdf/accessibility/pdf/text_font-embedding.pdf index 7ffb40af8..d1e4c6e28 100644 Binary files a/test/pdf/accessibility/pdf/text_font-embedding.pdf and b/test/pdf/accessibility/pdf/text_font-embedding.pdf differ -- cgit v1.2.3 From 47789800746b09c46b7369d9d8122b40531494e0 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Fri, 25 May 2012 20:02:21 +0000 Subject: Bugzilla #53294: Fix invalid PostScript file being created when font-size is 0. Submitted by Robert Meyer. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1342792 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/render/ps/PSPainter.java | 10 +++- status.xml | 3 + .../apache/fop/render/ps/PSPainterTestCase.java | 69 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/java/org/apache/fop/render/ps/PSPainterTestCase.java (limited to 'test') diff --git a/src/java/org/apache/fop/render/ps/PSPainter.java b/src/java/org/apache/fop/render/ps/PSPainter.java index 370472457..9bed2a432 100644 --- a/src/java/org/apache/fop/render/ps/PSPainter.java +++ b/src/java/org/apache/fop/render/ps/PSPainter.java @@ -74,10 +74,14 @@ public class PSPainter extends AbstractIFPainter { * @param documentHandler the parent document handler */ public PSPainter(PSDocumentHandler documentHandler) { + this(documentHandler, IFState.create()); + } + + protected PSPainter(PSDocumentHandler documentHandler, IFState state) { super(); this.documentHandler = documentHandler; this.borderPainter = new PSBorderPainter(documentHandler.gen); - this.state = IFState.create(); + this.state = state; } /** {@inheritDoc} */ @@ -346,6 +350,10 @@ public class PSPainter extends AbstractIFPainter { public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp, String text) throws IFException { try { + //Do not draw text if font-size is 0 as it creates an invalid PostScript file + if (state.getFontSize() == 0) { + return; + } PSGenerator generator = getGenerator(); generator.useColor(state.getTextColor()); beginTextObject(); diff --git a/status.xml b/status.xml index a41223e6c..22654f61c 100644 --- a/status.xml +++ b/status.xml @@ -63,6 +63,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Fix invalid PostScript file being created when font-size is 0. + Update FAQ and New Bug documentation. diff --git a/test/java/org/apache/fop/render/ps/PSPainterTestCase.java b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java new file mode 100644 index 000000000..4e50f09c9 --- /dev/null +++ b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java @@ -0,0 +1,69 @@ +/* + * 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. + */ +package org.apache.fop.render.ps; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.verification.VerificationMode; + +import org.apache.xmlgraphics.ps.PSGenerator; + +import org.apache.fop.render.intermediate.IFState; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class PSPainterTestCase { + + private PSDocumentHandler docHandler; + private PSPainter psPainter; + private PSGenerator gen; + private IFState state; + + @Before + public void setup() { + docHandler = new PSDocumentHandler(); + gen = mock(PSGenerator.class); + docHandler.gen = gen; + state = IFState.create(); + psPainter = new PSPainter(docHandler, state); + } + + @Test + public void testNonZeroFontSize() throws IOException { + testFontSize(6, times(1)); + } + + @Test + public void testZeroFontSize() throws IOException { + testFontSize(0, never()); + } + + private void testFontSize(int fontSize, VerificationMode test) throws IOException { + state.setFontSize(fontSize); + try { + psPainter.drawText(10, 10, 2, 2, null, "Test"); + } catch (Exception ex) { + //Expected + } + verify(gen, test).useColor(state.getTextColor()); + } +} -- cgit v1.2.3 From 72ba7e572dccdb5ab1930ed9f20c9db7f720ae50 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Sun, 27 May 2012 17:39:49 +0000 Subject: Add extension to place code just before PostScript %PageTrailer. Submitted by Luis Bernardo. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1343072 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/render/ps/PSDocumentHandler.java | 13 ++++- .../ps/extensions/PSExtensionElementMapping.java | 7 +++ .../render/ps/extensions/PSExtensionHandler.java | 3 ++ .../ps/extensions/PSPageTrailerCodeBefore.java | 50 ++++++++++++++++++++ .../extensions/PSPageTrailerCodeBeforeElement.java | 55 ++++++++++++++++++++++ status.xml | 3 ++ .../fop/render/ps/PSRenderingUtilTestCase.java | 45 ++++++++++++++++++ 7 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java create mode 100644 src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java create mode 100644 test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java (limited to 'test') diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java index 490e42b2d..95647d820 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -57,6 +58,7 @@ import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.IFPainter; import org.apache.fop.render.ps.extensions.PSCommentAfter; import org.apache.fop.render.ps.extensions.PSCommentBefore; +import org.apache.fop.render.ps.extensions.PSPageTrailerCodeBefore; import org.apache.fop.render.ps.extensions.PSSetPageDevice; import org.apache.fop.render.ps.extensions.PSSetupCode; @@ -98,10 +100,11 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { private PSPageDeviceDictionary pageDeviceDictionary; /** This is a collection holding all document header comments */ - private Collection[] comments = new Collection[3]; + private Collection[] comments = new Collection[4]; private static final int COMMENT_DOCUMENT_HEADER = 0; private static final int COMMENT_DOCUMENT_TRAILER = 1; private static final int COMMENT_PAGE_TRAILER = 2; + private static final int PAGE_TRAILER_CODE_BEFORE = 3; /** * Default constructor. @@ -443,8 +446,9 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { /** {@inheritDoc} */ public void startPageTrailer() throws IFException { - super.startPageTrailer(); try { + writeExtensions(PAGE_TRAILER_CODE_BEFORE); + super.startPageTrailer(); gen.writeDSCComment(DSCConstants.PAGE_TRAILER); } catch (IOException ioe) { throw new IFException("I/O error in startPageTrailer()", ioe); @@ -526,6 +530,11 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { comments[targetCollection] = new java.util.ArrayList(); } comments[targetCollection].add(extension); + } else if (extension instanceof PSPageTrailerCodeBefore) { + if (comments[PAGE_TRAILER_CODE_BEFORE] == null) { + comments[PAGE_TRAILER_CODE_BEFORE] = new ArrayList(); + } + comments[PAGE_TRAILER_CODE_BEFORE].add(extension); } } catch (IOException ioe) { throw new IFException("I/O error in handleExtensionObject()", ioe); diff --git a/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java b/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java index 00d0594f2..5721afaf6 100644 --- a/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java +++ b/src/java/org/apache/fop/render/ps/extensions/PSExtensionElementMapping.java @@ -41,6 +41,7 @@ public class PSExtensionElementMapping extends ElementMapping { foObjs = new java.util.HashMap(); foObjs.put(PSSetupCodeElement.ELEMENT, new PSSetupCodeMaker()); foObjs.put(PSPageSetupCodeElement.ELEMENT, new PSPageSetupCodeMaker()); + foObjs.put(PSPageTrailerCodeBefore.ELEMENT, new PSPageTrailerCodeBeforeMaker()); foObjs.put(PSSetPageDeviceElement.ELEMENT, new PSSetPageDeviceMaker()); foObjs.put(PSCommentBefore.ELEMENT, new PSCommentBeforeMaker()); foObjs.put(PSCommentAfter.ELEMENT, new PSCommentAfterMaker()); @@ -59,6 +60,12 @@ public class PSExtensionElementMapping extends ElementMapping { } } + static class PSPageTrailerCodeBeforeMaker extends ElementMapping.Maker { + public FONode make(FONode parent) { + return new PSPageTrailerCodeBeforeElement(parent); + } + } + static class PSSetPageDeviceMaker extends ElementMapping.Maker { public FONode make(FONode parent) { return new PSSetPageDeviceElement(parent); diff --git a/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java b/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java index d499ef6ab..b520d8736 100644 --- a/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java +++ b/src/java/org/apache/fop/render/ps/extensions/PSExtensionHandler.java @@ -53,6 +53,7 @@ public class PSExtensionHandler extends DefaultHandler lastAttributes = new AttributesImpl(attributes); handled = false; if (localName.equals(PSSetupCode.ELEMENT) + || localName.equals(PSPageTrailerCodeBefore.ELEMENT) || localName.equals(PSSetPageDevice.ELEMENT) || localName.equals(PSCommentBefore.ELEMENT) || localName.equals(PSCommentAfter.ELEMENT)) { @@ -84,6 +85,8 @@ public class PSExtensionHandler extends DefaultHandler this.returnedObject = new PSCommentBefore(content.toString()); } else if (PSCommentAfter.ELEMENT.equals(localName)) { this.returnedObject = new PSCommentAfter(content.toString()); + } else if (PSPageTrailerCodeBefore.ELEMENT.equals(localName)) { + this.returnedObject = new PSPageTrailerCodeBefore(content.toString()); } } content.setLength(0); //Reset text buffer (see characters()) diff --git a/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java b/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java new file mode 100644 index 000000000..f28f0003e --- /dev/null +++ b/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBefore.java @@ -0,0 +1,50 @@ +/* + * 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.render.ps.extensions; + + +public class PSPageTrailerCodeBefore extends PSExtensionAttachment { + + /** The element name */ + protected static final String ELEMENT = "ps-page-trailer-code-before"; + + /** + * Default constructor + * @param content the actual comment + */ + public PSPageTrailerCodeBefore(String content) { + super(content); + } + + /** + * Constructor + */ + public PSPageTrailerCodeBefore() { + super(); + } + + /** + * @return element name + */ + protected String getElement() { + return ELEMENT; + } + +} diff --git a/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java b/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java new file mode 100644 index 000000000..65a22eadd --- /dev/null +++ b/src/java/org/apache/fop/render/ps/extensions/PSPageTrailerCodeBeforeElement.java @@ -0,0 +1,55 @@ +/* + * 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.render.ps.extensions; + +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.extensions.ExtensionAttachment; + +/** + * Comment before element + */ +public class PSPageTrailerCodeBeforeElement extends AbstractPSCommentElement { + + /** the element name */ + protected static final String ELEMENT = "ps-page-trailer-code-before"; + + /** + * Main constructor + * @param parent parent node + */ + public PSPageTrailerCodeBeforeElement(FONode parent) { + super(parent); + } + + /** + * @return local name + * @see org.apache.fop.fo.FONode#getLocalName() + */ + public String getLocalName() { + return PSPageTrailerCodeBefore.ELEMENT; + } + + /** + * @return instance of its extension attachment object + */ + protected ExtensionAttachment instantiateExtensionAttachment() { + return new PSPageTrailerCodeBefore(); + } +} diff --git a/status.xml b/status.xml index 22654f61c..a18de8fca 100644 --- a/status.xml +++ b/status.xml @@ -63,6 +63,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Add extension to place code just before PostScript %PageTrailer. + Fix invalid PostScript file being created when font-size is 0. diff --git a/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java b/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java new file mode 100644 index 000000000..3f1088fe1 --- /dev/null +++ b/test/java/org/apache/fop/render/ps/PSRenderingUtilTestCase.java @@ -0,0 +1,45 @@ +/* + * 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.render.ps; + +import java.io.IOException; + +import org.junit.Test; + +import org.apache.xmlgraphics.ps.PSGenerator; + +import org.apache.fop.render.ps.extensions.PSPageTrailerCodeBefore; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class PSRenderingUtilTestCase { + + private final String content = "<< /MyEntry 0 >> command"; + private final PSPageTrailerCodeBefore ptcb = new PSPageTrailerCodeBefore(content); + private final PSGenerator gen = mock(PSGenerator.class); + + @Test + public void testWriteEnclosedExtensionAttachment() throws IOException { + PSRenderingUtil.writeEnclosedExtensionAttachment(gen, ptcb); + verify(gen).writeln(content); + } + +} -- cgit v1.2.3 From d48e0e1f467c58a22c4d1b19591d4fa9d22aa8c6 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Mon, 28 May 2012 03:30:37 +0000 Subject: Add version attribute to AT and IF intermediate formats. Also eliminate redundant use of reversed attribute in AT format. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1343133 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop-intermediate-format-ng.xsd | 1 + .../fop/render/intermediate/IFSerializer.java | 13 ++++++++++- .../org/apache/fop/render/xml/XMLRenderer.java | 26 +++++++++++++++++----- status.xml | 3 +++ .../standard-testcases/bidi_propagation_1.xml | 4 ++-- .../character_writing-mode_rl.xml | 10 ++++----- 6 files changed, 44 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd b/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd index bea5275a5..6e17c793b 100644 --- a/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd +++ b/src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd @@ -34,6 +34,7 @@ + diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java index f8f286cb3..7114f51e3 100644 --- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java +++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java @@ -64,6 +64,15 @@ import org.apache.fop.util.XMLUtil; public class IFSerializer extends AbstractXMLWritingIFDocumentHandler implements IFConstants, IFPainter, IFDocumentNavigationHandler { + /** + * Intermediate Format (IF) version, used to express an @version attribute + * in the root element of the IF document, the initial value of which + * is set to '2.0' to signify that something preceded it (but didn't + * happen to be marked as such), and that this version is not necessarily + * backwards compatible with the unmarked (<2.0) version. + */ + public static final String VERSION = "2.0"; + private IFDocumentHandler mimicHandler; private int pageSequenceIndex; // used for accessibility @@ -167,7 +176,9 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler DocumentNavigationExtensionConstants.NAMESPACE); handler.startPrefixMapping(InternalElementMapping.STANDARD_PREFIX, InternalElementMapping.URI); - handler.startElement(EL_DOCUMENT); + AttributesImpl atts = new AttributesImpl(); + addAttribute(atts, "version", VERSION); + handler.startElement(EL_DOCUMENT, atts); } catch (SAXException e) { throw new IFException("SAX error in startDocument()", e); } diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 4ac650269..cf3cbe5a2 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -97,6 +97,15 @@ import org.apache.fop.util.XMLUtil; */ public class XMLRenderer extends AbstractXMLRenderer { + /** + * Area Tree (AT) version, used to express an @version attribute + * in the root element of the AT document, the initial value of which + * is set to '2.0' to signify that something preceded it (but didn't + * happen to be marked as such), and that this version is not necessarily + * backwards compatible with the unmarked (<2.0) version. + */ + public static final String VERSION = "2.0"; + /** XML MIME type */ public static final String XML_MIME_TYPE = MimeConstants.MIME_FOP_AREA_TREE; @@ -365,7 +374,9 @@ public class XMLRenderer extends AbstractXMLRenderer { if (userAgent.getProducer() != null) { comment("Produced by " + userAgent.getProducer()); } - startElement("areaTree"); + atts.clear(); + addAttribute("version", VERSION); + startElement("areaTree", atts); } /** {@inheritDoc} */ @@ -825,11 +836,10 @@ public class XMLRenderer extends AbstractXMLRenderer { } maybeAddLevelAttribute(word); maybeAddPositionAdjustAttribute(word); - if ( word.isReversed() ) { - addAttribute("reversed", "true"); - } + String text = word.getWord(); + maybeAddReversedAttribute(word, text); startElement("word", atts); - characters(word.getWord()); + characters(text); endElement("word"); super.renderWord(word); } @@ -917,5 +927,11 @@ public class XMLRenderer extends AbstractXMLRenderer { } } + private void maybeAddReversedAttribute ( WordArea w, String text ) { + if ( w.isReversed() && ( text.length() > 1 ) ) { + addAttribute("reversed", "true"); + } + } + } diff --git a/status.xml b/status.xml index a18de8fca..6b1c4b849 100644 --- a/status.xml +++ b/status.xml @@ -63,6 +63,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Add version attribute to AT and IF intermediate formats. Also eliminate redundant use of reversed attribute in AT format. + Add extension to place code just before PostScript %PageTrailer. diff --git a/test/layoutengine/standard-testcases/bidi_propagation_1.xml b/test/layoutengine/standard-testcases/bidi_propagation_1.xml index 947d9dac5..587bc6d2f 100644 --- a/test/layoutengine/standard-testcases/bidi_propagation_1.xml +++ b/test/layoutengine/standard-testcases/bidi_propagation_1.xml @@ -66,7 +66,7 @@ - X + XY @@ -93,7 +93,7 @@ - X + XY diff --git a/test/layoutengine/standard-testcases/character_writing-mode_rl.xml b/test/layoutengine/standard-testcases/character_writing-mode_rl.xml index adc126ec8..db65238c0 100644 --- a/test/layoutengine/standard-testcases/character_writing-mode_rl.xml +++ b/test/layoutengine/standard-testcases/character_writing-mode_rl.xml @@ -59,18 +59,18 @@ - + - - + + - + - + -- cgit v1.2.3