From 2654b604ede6894bf6c69a56879c74e4c6193e42 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Wed, 27 Jul 2011 15:57:45 +0000 Subject: [PATCH] output language in (Word) XSL FO git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1151511 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hwpf/converter/AbstractWordUtils.java | 23 +++++++++++++++++++ .../poi/hwpf/converter/WordToFoUtils.java | 8 ++++++- .../poi/hwpf/usermodel/CharacterRun.java | 4 ++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java index ef1d82a75b..5e4dc65426 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -23,6 +23,9 @@ import java.io.InputStream; import java.util.Set; import java.util.TreeSet; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; + import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; import org.apache.poi.hwpf.HWPFOldDocument; @@ -46,6 +49,9 @@ public class AbstractWordUtils { static final String EMPTY = ""; + private static final POILogger logger = POILogFactory + .getLogger( AbstractWordUtils.class ); + public static final float TWIPS_PER_INCH = 1440.0f; public static final int TWIPS_PER_PT = 20; @@ -377,6 +383,23 @@ public class AbstractWordUtils return ""; } + public static String getLanguage( int languageCode ) + { + switch ( languageCode ) + { + case 1033: + return "en-us"; + case 1049: + return "ru-ru"; + case 2057: + return "en-uk"; + default: + logger.log( POILogger.WARN, "Uknown or unmapped language code: ", + Integer.valueOf( languageCode ) ); + return ""; + } + } + public static String getListItemNumberLabel( int number, int format ) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java index 783896f096..202341fcee 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java @@ -74,6 +74,12 @@ public class WordToFoUtils extends AbstractWordUtils { inline.setAttribute( "color", getColor24( characterRun.getIco24() ) ); } + if ( characterRun.getLanguageCode() != 0 ) + { + final String language = getLanguage( characterRun.getLanguageCode() ); + if ( isNotEmpty( language ) ) + inline.setAttribute( "language", language ); + } if ( characterRun.isCapitalized() ) { inline.setAttribute( "text-transform", "uppercase" ); @@ -273,7 +279,7 @@ public class WordToFoUtils extends AbstractWordUtils graphicElement.setAttribute( "clip", "rect(" + rectTop + "pt, " + rectRight + "pt, " + rectBottom + "pt, " + rectLeft + "pt)" ); - graphicElement.setAttribute( "oveerflow", "hidden" ); + graphicElement.setAttribute( "overflow", "hidden" ); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java index d1ea206872..61be15b668 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java @@ -620,6 +620,10 @@ public final class CharacterRun return _props.getBrc(); } + public int getLanguageCode() { + return _props.getLidDefault(); + } + public String toString() { String text = text(); return "CharacterRun of " + text.length() + " characters - " + text; -- 2.39.5