You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "vikas kumar jagga (JIRA)" <ji...@apache.org> on 2018/04/06 06:18:00 UTC

[jira] [Created] (PDFBOX-4183) To support multi-lingual paragraphs without switching Font objects

vikas kumar jagga created PDFBOX-4183:
-----------------------------------------

             Summary: To support multi-lingual paragraphs without switching Font objects
                 Key: PDFBOX-4183
                 URL: https://issues.apache.org/jira/browse/PDFBOX-4183
             Project: PDFBox
          Issue Type: New Feature
          Components: FontBox
            Reporter: vikas kumar jagga


Problem :- If a single paragraph has fonts of different languages we need to detect the language and load the appropriate PDType0Font font file object (holding ttf file) supporting that language fonts.

PDFbox library should provide a class with addFont() method that can hold multiple PDType0Font objects (holding different ttf files) so that this object holding multiple font files could be loaded in document object. It will reduce the overhead to detect the language and then loading that ttf file object.

iText provide this feature with FontSelector class. Below is the sample code usage.


{color:#14892c}import java.awt.Color;{color}

{color:#14892c}import org.apache.log4j.Logger;{color}

{color:#14892c}import com.lowagie.text.Font;{color}
{color:#14892c}import com.lowagie.text.pdf.BaseFont;{color}
{color:#14892c}import com.lowagie.text.pdf.FontSelector;{color}

{color:#14892c}public class Fonts {{color}

{color:#14892c}public static final int STYLE_BOLD = Font.BOLD;{color}
{color:#14892c} public static final int STYLE_BOLDITALIC = Font.BOLDITALIC;{color}
{color:#14892c} public static final int STYLE_ITALIC = Font.ITALIC;{color}
{color:#14892c} public static final int STYLE_NORMAL = Font.NORMAL;{color}
{color:#14892c} public static final int STYLE_STRIKETHROUGH = Font.STRIKETHRU;{color}
{color:#14892c} public static final int STYLE_UNDERLINE = Font.UNDERLINE;{color}


{color:#14892c} public static final BaseFont FONT_NOTO_SANS;{color}
{color:#14892c} public static final BaseFont FONT_NOTO_SANS_AR; // Arabic{color}
{color:#14892c} public static final BaseFont FONT_NOTO_SANS_TH; // Thai{color}
{color:#14892c} public static final BaseFont FONT_NOTO_SANS_CJK; // Chinese, Japanese and Korean{color}

{color:#14892c}static {{color}

{color:#14892c}try {{color}
{color:#14892c} tmpNOTOSANS = BaseFont.createFont("/fonts/NotoSans-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);{color}
{color:#14892c} }{color}
{color:#14892c} catch (Exception ex) {{color}
 
{color:#14892c} }{color}

{color:#14892c}try {{color}
{color:#14892c} tmpNOTOSANS_AR = BaseFont.createFont("/fonts/NotoKufiArabic-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);{color}
{color:#14892c} }{color}
{color:#14892c} catch (Exception ex) {{color}
 
{color:#14892c} }{color}

{color:#14892c}try {{color}
{color:#14892c} tmpNOTOSANS_TH = BaseFont.createFont("/fonts/NotoSansThai-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);{color}
{color:#14892c} }{color}
{color:#14892c} catch (Exception ex) {{color}
 
{color:#14892c} }{color}

{color:#14892c}try {{color}
{color:#14892c} tmpNOTOSANS_CJK = BaseFont.createFont("/fonts/NotoSansCJK-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);{color}
{color:#14892c} }{color}
{color:#14892c} catch (Exception ex) {{color}
 
{color:#14892c} }{color}
 
{color:#14892c} FONT_NOTO_SANS = tmpNOTOSANS;{color}
{color:#14892c} FONT_NOTO_SANS_AR = tmpNOTOSANS_AR;{color}
{color:#14892c} FONT_NOTO_SANS_TH = tmpNOTOSANS_TH;{color}
{color:#14892c} FONT_NOTO_SANS_CJK = tmpNOTOSANS_CJK;{color}
{color:#14892c} }{color}

{color:#14892c}public static FontSelector returnFontSelector(float size, int style) {{color}
{color:#14892c} return returnFontSelector(size, style, null);{color}
{color:#14892c} }{color}

{color:#14892c}public static FontSelector returnFontSelector(float size, int style, Color color) {{color}
{color:#14892c} FontSelector multiFonts = new FontSelector();{color}
 
{color:#14892c} multiFonts.addFont(new Font(Fonts.FONT_NOTO_SANS, size, style, color));{color}
{color:#14892c} multiFonts.addFont(new Font(Fonts.FONT_NOTO_SANS_AR, size, style, color));{color}
{color:#14892c} multiFonts.addFont(new Font(Fonts.FONT_NOTO_SANS_TH, size, style, color));{color}
{color:#14892c} multiFonts.addFont(new Font(Fonts.FONT_NOTO_SANS_CJK, size, style, color));{color}
 
{color:#14892c} return multiFonts;{color}
{color:#14892c} }{color}

{color:#14892c}}{color}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org