Etienne-Gautier opened a new pull request, #986:
URL: https://github.com/apache/poi/pull/986

   # Context
   I'd like to better support DOCX theme fonts, but currently they are 
inaccessible.
   
   For anyone interested, a run can define fonts either
   - directly `"ascii"="Times New Roman"`
   - indirectly via a theme
   
   Currently the XWPFTheme doesn't expose major/minor fonts to resolve theme 
fonts, so I am fixing that in this PR.
   
   Note: I spent a bit of time figuring out how the theme fonts are resolved 
and I thought I'd write it down somewhere. So for anyone interested, a run 
might look like this:
   ```xml
       <w:r>
         <w:rPr>
           <w:rFonts w:ascii="Aleo" w:asciiTheme="majorBidi" 
w:hAnsiTheme="majorBidi" w:cstheme="majorBidi"/>
         </w:rPr>
         <w:t>Some text with font from theme</w:t>
       </w:r>
   ```
   
   With settings containing 
   ```xml
     <w:themeFontLang w:val="en-AU" w:bidi="ja-JP"/>
   ```
   
   And a Theme like this:
   
   ```xml
       <a:fontScheme name="Office">
         <a:majorFont>
           <a:latin typeface="Aptos Display" panose="02110004020202020204"/>
           <a:ea typeface=""/>
           <a:cs typeface="Segoe UI"/>
           <a:font script="Jpan" typeface="游ゴシック Light"/>
       </a:majorFont>
       <a:minorFont>
           <a:latin typeface="Aptos" panose="02110004020202020204"/>
           <a:ea typeface=""/>
           <a:cs typeface=""/>
           <a:font script="Jpan" typeface="游明朝"/>
       </a:minorFont>
   ```
   
   This theme font can be interpreted by combining info from the document 
settings (`themeFontLang`) and themes. There is an explanation of that in the 
spec at `17.15.1.88 themeFontLang (Theme Font Languages)`. However that 
explanation doesn't really tell you how to map the locale code (for example 
`ja-JP`) from `themeFontLang` to a script (for example `Jpan`).
   
   I found that:
   - POI's `LocaleID.lookupByLanguageTag(localeName)` can read the locale.
   - Then the logic from Libreoffice 
[here](https://github.com/LibreOffice/core/blob/master/sw/source/writerfilter/dmapper/ThemeHandler.cxx#L21)
 can easily be ported from java to map a `localeID.getLcid()` to a script. We 
can then lookup the major/minor theme font with that script
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to