Skip to content

Commit

Permalink
Docx writer: add eastAsia font hints to w:r.
Browse files Browse the repository at this point in the history
We do this when the text in the run contains any CJK characters.
This ensures that ambiguous code points (e.g. quotation marks)
will be represented as "wide" characters when together with CJK
characters.

Closes #9817.
  • Loading branch information
jgm committed May 29, 2024
1 parent 2f1f066 commit a6c3945
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Text/Pandoc/Writers/Docx/OpenXML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Control.Applicative ((<|>))
import Control.Monad.Except (catchError)
import qualified Data.ByteString.Lazy as BL
import Data.Char (isLetter)
import Text.Pandoc.Char (isCJK)
import Data.Ord (comparing)
import Data.String (fromString)
import qualified Data.Map as M
Expand Down Expand Up @@ -593,8 +594,13 @@ formattedString str =
formattedString' :: PandocMonad m => Text -> WS m [Element]
formattedString' str = do
inDel <- asks envInDel
formattedRun [ mktnode (if inDel then "w:delText" else "w:t")
[("xml:space","preserve")] (stripInvalidChars str) ]
let addFontProp
| T.any isCJK str
= withTextProp (mknode "w:rFonts" [("w:hint","eastAsia")] ())
| otherwise = id
addFontProp $
formattedRun [ mktnode (if inDel then "w:delText" else "w:t")
[("xml:space","preserve")] (stripInvalidChars str) ]

formattedRun :: PandocMonad m => [Element] -> WS m [Element]
formattedRun els = do
Expand Down
Binary file modified test/docx/golden/unicode.docx
Binary file not shown.

0 comments on commit a6c3945

Please sign in to comment.