Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTL support when using Apache POI with openPdf #549

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8ba0558
Update pom.xml
nucleussoftwareopen Jan 7, 2021
f9a769c
Update pom.xml
nucleussoftwareopen Jan 7, 2021
66313d3
Update pom.xml
nucleussoftwareopen Jan 7, 2021
cbd3875
Update pom.xml
nucleussoftwareopen Jan 7, 2021
6d08e80
Update pom.xml
nucleussoftwareopen Jan 7, 2021
689d910
Update StyleTableCell
nucleussoftwareopen Jan 7, 2021
5814edc
Update PdfMapper.java
nucleussoftwareopen Jan 7, 2021
8d7516c
Update pom.xml
nucleussoftwareopen Jan 7, 2021
4451ce8
Update XWPFStylesDocument.java
nucleussoftwareopen Jan 7, 2021
823868f
Update PdfConverterTestCase.java
nucleussoftwareopen Jan 7, 2021
628377e
Update XHTMLConverterEmbedImgTest.java
nucleussoftwareopen Jan 7, 2021
776d8ff
Update XHTMLConverterTestCase.java
nucleussoftwareopen Jan 7, 2021
88999aa
Update ODTDefaultStylesGenerator.java
nucleussoftwareopen Jan 7, 2021
e69c804
Update StylesHelper.java
nucleussoftwareopen Jan 7, 2021
8b356b9
Update ContainerProperties.java
nucleussoftwareopen Jan 7, 2021
3fad91b
Update ExtendedChapter.java
nucleussoftwareopen Jan 7, 2021
e238556
Update ExtendedChapterAutoNumber.java
nucleussoftwareopen Jan 7, 2021
83b35c3
Update ExtendedSection.java
nucleussoftwareopen Jan 7, 2021
b825f97
Update PdfMapper.java
nucleussoftwareopen Jan 7, 2021
24df3dd
Update PdfMapper.java
nucleussoftwareopen Jan 7, 2021
3421b36
Update FastPdfMapper.java
nucleussoftwareopen Jan 7, 2021
6d62702
Update StylableAnchor.java
nucleussoftwareopen Jan 7, 2021
cda370e
Update StylableList.java
nucleussoftwareopen Jan 7, 2021
7337d94
Update StylableParagraph.java
nucleussoftwareopen Jan 7, 2021
c55691e
Update StylablePhrase.java
nucleussoftwareopen Jan 7, 2021
0a52fad
Update StylableAnchor.java
nucleussoftwareopen Jan 7, 2021
f0e36a3
Update StylableList.java
nucleussoftwareopen Jan 7, 2021
6f1774f
RTL support when using Apache POI with openPdf
Apr 20, 2022
4221639
Adding RTL support for ODT document conversion to PDF.
Jun 29, 2022
ac79202
Empty char should not be replaced with space as it causes multiple ex…
Jul 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,10 @@ public String getTextStyleName( ContainerProperties properties )
startStyleIfNeeded(properties.getType(), properties.getStyleName());
dynamicStyles.append( "style:text-position=\"super\" " );
}

if (properties.getBackgroundColor() != null){
startStyleIfNeeded(properties.getType());
dynamicStyles.append( "fo:background-color=\""+ properties.getBackgroundColor()+ "\" ");
}
// <style:paragraph-properties fo:text-align="center" style:justify-single-word="false" />
setPropertiesKind( ODTStyleProperties.PARAGRAPH );
TextAlignment textAlignment = properties.getTextAlignment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ else if ( "inherit".equals( textAlignment ) )
}

}

String backgroundColor = stylesMap.get("background-color");
if(backgroundColor != null) {
properties.setBackgroundColor(backgroundColor);
}

// style
String styleName = stylesMap.get("name");
if (styleName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public enum ContainerType
private String styleName;

private final ContainerType type;

private String backgroundColor;

public ContainerProperties( ContainerType type )
{
Expand Down Expand Up @@ -164,5 +166,15 @@ public String getStyleName() {
public void setStyleName(String styleName) {
this.styleName = styleName;
}


public String getBackgroundColor() {
return backgroundColor;
}

public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>thirdparties-extension</artifactId>
<version>2.0.2</version>
<version>2.0.2.1</version>
</parent>
<dependencies>
<dependency>
Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.itext.extension</artifactId>
<version>2.0.2</version>
<version>2.0.2.1</version>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ else if ( FoBreakBeforeAttribute.Value.COLUMN.toString().equals( breakBefore ) )
paragraphProperties.setBreakBefore( StyleBreak.createWithNoBreak() );
}
}

// writing-mode
String writingMode = ele.getStyleWritingModeAttribute();
if ( StringUtils.isNotEmpty( writingMode ) ){
paragraphProperties.setWritingMode( writingMode );
}

super.visit( ele );
}
Expand Down Expand Up @@ -1134,6 +1140,12 @@ else if ( TableAlignAttribute.Value.RIGHT.toString().equals( align ) )
tableProperties.setMayBreakBetweenRows( mayBreakBetweenRows );
}

// writing-mode
String writingMode = ele.getStyleWritingModeAttribute();
if ( StringUtils.isNotEmpty( writingMode ) ){
tableProperties.setWritingMode( writingMode );
}

super.visit( ele );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ public IStylableContainer getParent()
public Element getElement()
{
// underline font if not explicitly set
ArrayList<Chunk> chunks = getChunks();
for ( Chunk chunk : chunks )
ArrayList chunks = getChunks();
for ( Object elem : chunks )
{
Chunk chunk = (Chunk)elem;
Font f = chunk.getFont();
if ( f != null && !f.isUnderlined() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ private void addElement( Element element, boolean addLabel )
Font symbolFont = symbol.getFont();
if ( symbolFont.isStandardFont() )
{
ArrayList<Chunk> chunks = p.getChunks();
for ( Chunk chunk : chunks )
ArrayList chunks = p.getChunks();
for ( Object elem : chunks )
{
Chunk chunk = (Chunk)elem;
// use first specified font
if ( !chunk.getFont().isStandardFont() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;

import com.lowagie.text.pdf.PdfWriter;
import fr.opensagres.odfdom.converter.core.utils.ODFUtils;
import fr.opensagres.odfdom.converter.pdf.internal.styles.Style;
import fr.opensagres.odfdom.converter.pdf.internal.styles.StyleBreak;
Expand Down Expand Up @@ -147,6 +148,19 @@ public void applyStyles( Style style )
{
super.setKeepTogether( keepTogether );
}

// Support for writing mode i.e. LTR OR RTL
String writingMode = paragraphProperties.getWritingMode();
if ( writingMode != null && writingMode.equals("rl-tb"))
{
// RTL
super.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
}
else{
// LTR
super.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
}

}
}

Expand Down Expand Up @@ -222,9 +236,10 @@ private void postProcessEmptyParagraph()
// add space if this paragraph is empty
// otherwise its height will be zero
boolean empty = true;
ArrayList<Chunk> chunks = getChunks();
for ( Chunk chunk : chunks )
ArrayList chunks = getChunks();
for ( Object elem : chunks )
{
Chunk chunk = (Chunk)elem;
if ( chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0 )
{
empty = false;
Expand All @@ -242,10 +257,10 @@ private void postProcessBookmarks()
{
// add space if last chunk is a bookmark
// otherwise the bookmark will disappear from pdf
ArrayList<Chunk> chunks = getChunks();
ArrayList chunks = getChunks();
if ( chunks.size() > 0 )
{
Chunk lastChunk = chunks.get( chunks.size() - 1 );
Chunk lastChunk = (Chunk)chunks.get( chunks.size() - 1 );
String localDestination = null;
if ( lastChunk.getAttributes() != null )
{
Expand Down Expand Up @@ -289,9 +304,10 @@ private void postProcessLineHeightAndBaseline()
// again this may be inaccurate if fonts with different size are used in this paragraph
float itextdescender = -font.getBaseFont().getFontDescriptor( BaseFont.DESCENT, size ); // negative
float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier;
ArrayList<Chunk> chunks = getChunks();
for ( Chunk chunk : chunks )
ArrayList chunks = getChunks();
for ( Object elem : chunks )
{
Chunk chunk = (Chunk)elem;
Font f = chunk.getFont();
if ( f != null )
{
Expand Down Expand Up @@ -323,9 +339,10 @@ private Font getMostOftenUsedFont()
Map<String, Integer> countMap = new LinkedHashMap<String, Integer>();
Font mostUsedFont = null;
int mostUsedCount = -1;
ArrayList<Chunk> chunks = getChunks();
for ( Chunk chunk : chunks )
ArrayList chunks = getChunks();
for ( Object elem : chunks )
{
Chunk chunk = (Chunk)elem;
Font font = chunk.getFont();
int count = 0;
String text = chunk.getContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public IStylableContainer getParent()
public Element getElement()
{
boolean empty = true;
ArrayList<Chunk> chunks = getChunks();
for ( Chunk chunk : chunks )
ArrayList chunks = getChunks();
for ( Object elem : chunks )
{
Chunk chunk = (Chunk)elem;
if ( chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0 )
{
empty = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.lowagie.text.Element;

import com.lowagie.text.pdf.PdfWriter;
import fr.opensagres.odfdom.converter.pdf.internal.styles.Style;
import fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTableProperties;
import fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTableRowProperties;
Expand Down Expand Up @@ -131,7 +132,7 @@ public void applyStyles( Style style )

// alignment
int alignment = tableProperties.getAlignment();
if ( alignment != Element.ALIGN_UNDEFINED )
if (alignment != Element.ALIGN_UNDEFINED && style.getFamilyName().equals("table"))
{
super.setHorizontalAlignment( alignment );
}
Expand Down Expand Up @@ -169,6 +170,14 @@ public void applyStyles( Style style )
{
super.setKeepTogether( !mayBreakBetweenRows );
}

// Support for writing mode i.e. LTR OR RTL
String writingMode = tableProperties.getWritingMode();
if ( writingMode != null && writingMode.equals("rl-tb"))
{
// RTL
super.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
}
}
StyleTableRowProperties tableRowProperties = style.getTableRowProperties();
if ( tableRowProperties != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class StyleParagraphProperties
private Float paddingTop;

private Float textIndent;

private String writingMode;

public StyleParagraphProperties()
{
Expand Down Expand Up @@ -185,6 +187,9 @@ public void merge( StyleParagraphProperties paragraphProperties )
{
textIndent = paragraphProperties.getTextIndent();
}
if(paragraphProperties.getWritingMode() != null){
writingMode = paragraphProperties.getWritingMode();
}
}

public int getAlignment()
Expand Down Expand Up @@ -416,4 +421,14 @@ public void setTextIndent( Float textIndent )
{
this.textIndent = textIndent;
}

public String getWritingMode()
{
return writingMode;
}

public void setWritingMode( String writingMode )
{
this.writingMode = writingMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class StyleTableProperties

private Float width;

private String writingMode;

public StyleTableProperties()
{
}
Expand Down Expand Up @@ -98,6 +100,10 @@ public void merge( StyleTableProperties tableProperties )
{
width = tableProperties.getWidth();
}
if ( tableProperties.getWritingMode() != null )
{
writingMode = tableProperties.getWritingMode();
}
}

public int getAlignment()
Expand Down Expand Up @@ -189,4 +195,12 @@ public void setWidth( Float width )
{
this.width = width;
}

public String getWritingMode() {
return writingMode;
}

public void setWritingMode(String writingMode) {
this.writingMode = writingMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
<version>3.11</version>
<exclusions>
<!-- this artifact contains a subset of org.apache.poi:ooxml-schemas -->
<exclusion>
Expand Down
Loading