Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Arial Unicode MS to CKEditor

My web application allows user to write rich text inside CKEditor, then export the result as PDF with the Flying Saucer library.

As they need to write Greek characters, I chose to add Arial Unicode MS to the available fonts, by doing the following :

config.font_names = "*several fonts...*; Arial Unicode MS/Arial Unicode MS, serif";

This font is now displayed correctly in the CKEditor menu, but when I apply this font to any element, I get the following result :

<span style="font-family:arial unicode ms,serif;"> some text </span>

As you can notice, I lost the UpperCase characters. This has pretty bad effect during PDF export, as then Flying Saucer doesn't recognise the font and so uses Helvetica which does not support Unicode characters, so the greek characters are not displayed in the PDF.

If I change manually from code source

<span style="font-family:arial unicode ms,serif;"> some text </span>

to

<span style="font-family:Arial Unicode MS,serif;"> some text </span>

then it is working as expected, greek characters are displayed.

Has anyone met this problem before? Is there a way to avoid UpperCase characters to be changed to LowerCase? I really want to avoid doing any kind of post-processing like :

htmlString = htmlString.replace("arial unicode ms", "Arial Unicode MS");
like image 497
realUser404 Avatar asked May 28 '15 14:05

realUser404


People also ask

How do I add Arial Unicode?

Next to Office Shared Features, click the plus sign (+). Next to International Support, click the plus sign (+). Click the icon next to Universal Font, and then select the installation option you want. Arial Unicode MS must be used to fully implement the Symbol Table in SirsiDynix's clients.

Can I use Arial Unicode MS?

Arial Unicode MS is no longer available in Microsoft Office 2016, as it has been judged to no longer be suitable as a fallback font.

What happened to Arial Unicode MS?

When Microsoft included Arial Unicode MS with earlier versions of Office, Microsoft paid a licensing fee to The Monotype Corporation, which is the copyright holder for the font. Someone at Microsoft decided it was no longer worthwhile to continue paying that fee, so it was removed from the Office package.

What is Arial Unicode MS regular?

Overview. Arial Unicode MS was originally commissioned by Microsoft Office as an extended version of the Arial typeface to support a large set of international characters. The font was included with Office but not Windows.


3 Answers

I agree with you regarding resolving this issue aside from Flying Saucer R8. Although depending upon your workflow, would it be more efficient to allow CKEditor to preprocess and validate a completed HTML encoded file (render the entire document to HTML first)?

None of the CKEditor support tickets specify the true source of the issue, so I recommend confirming for yourself whether it is (A) a styling issue, or (B) a CSS processing issue, or (C) a peculiar CKEditor parsing issue.

A possible workaround: Make a copy of the desired unicode font and import it into Type 3.2 (works on both Mac and Windows).

http://www.cr8software.net/type.html

rename the duplicate font set into something all lowercase.

Limit your font selection

config.font_names = "customfontnamehere";

Apply the style separately (unicode typeface greatvibes below) and see if that gives you the desired result:

var s = CKEDITOR.document.$.createElement( 'style' );
s.type = 'text/css';
cardElement.$.appendChild( s );

s.styleSheet.cssText =
'@font-face {' +
'font-family: \'GreatVibes\';' +
'src: url(\'' + path +'fonts/GreatVibes-Regular.eot\');' +
'}' +
style;

If the above does not work, you can try to modify the xmas plugin.js (also uses the unicode typeface greatvibes and does all sorts of cool manipulations before output), so it might be worth trying to modify it rather than start from scratch:

'<style type="text/css">' +
'@font-face {' +
'font-family: "GreatVibes";' +
'src: url("' + path +'fonts/GreatVibes-Regular.ttf");' +
'}' +
style +
'</style>' )

Whichever approach you try, the goal is to test various styling and see if CKEditor defaults back to Helvetica again.

Lastly, the CKEditor SDK has excellent support, so if you have the time and energy, you could write a plugin. Sounds daunting, I know, but notice how the plugin.js within the /plugins/font directory has priority for size attributes.

If you are not interested in producing your own plugin, I recommend contacting the prolific ckeditor plugin writer

doksoft

(listed both on their website and on his own website) and ask for a demo of his commercial plugin "CKEditor Special Symbols" which has broad unicode capability. Hope that helps, ClaireW

like image 120
ClaireW Avatar answered Oct 19 '22 03:10

ClaireW


I didn't find any way to do it with Flying Saucer R8, but you can make it work using Flying Saucer R9.

The method ITextResolver.addFont(String path, String fontFamilyNameOverride, String encoding, boolean embedded, String pathToPFB) allow you to add the fond with a specific name.

Code sample:

  ITextRenderer renderer = new ITextRenderer();
  // Adding fonts
  renderer.getFontResolver().addFont("fonts/ARIALUNI.TTF", "arial unicode ms", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null);
  renderer.getFontResolver().addFont("fonts/ARIALUNI.TTF", "Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null);

  String inputFile = "test.html";
  renderer.setDocument(new File(inputFile));
  renderer.layout();

  String outputFile = "test.pdf";
  OutputStream os = new FileOutputStream(outputFile);
  renderer.createPDF(os);
  os.close();

You can find Flying Saucer R9 on Maven.

like image 2
obourgain Avatar answered Oct 19 '22 03:10

obourgain


The simplest solution (until CKEditor fixes that bug) is to do that post-processing.

You can do it on the server (really simple, you already have the code) or with a little CKEditor plugin, but that will give you the solution that you want and unless you need to add more fonts it will work without any further changes.

like image 2
AlfonsoML Avatar answered Oct 19 '22 03:10

AlfonsoML