Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new 'lang' text option to enable Chinese Word font_face to take effect #174

Closed
eddyclock opened this issue Sep 7, 2017 · 6 comments
Closed
Assignees
Milestone

Comments

@eddyclock
Copy link

eddyclock commented Sep 7, 2017

Hi @gitbrent ,

I have added some text with Chinese word "你好" with Chinese font_face = 微軟正黑體 but the chinese cannot reflect correctly.

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();
//chinese word with chinese font
slide.addText('你好',  { x:0.5, y:1, w:3, font_size:500 , font_face:'微軟正黑體'});
pptx.save('PptxGenJS-ChineseWord-Font-微軟正黑體');

image

I tried to add new option with "zh-tw"

if (opts.lang == "zh-TW"){
	startInfo = '<a:rPr lang="zh-TW" altLang="en-US" ';
}else{
	startInfo = '<a:rPr lang="en-US" ';
}
startInfo += ( opts.bold      ? ' b="1"' : '' );
startInfo += ( opts.font_size ? ' sz="'+ Math.round(opts.font_size) +'0"' : '' ); 
startInfo += ( opts.italic    ? ' i="1"' : '' );
startInfo += ( opts.underline || opts.hyperlink ? ' u="sng"' : '' );
// not doc in API yet: startInfo += ( opts.char_spacing ? ' spc="' + (text_info.char_spacing * 100) + '" kern="0"' : '' ); // IMPORTANT: Also disable kerning; otherwise text won't actually expand
startInfo += ' dirty="0" smtClean="0">';
// Color and Font are children of <a:rPr>, so add them now before closing the runProperties tag
if ( opts.color || opts.lang) {
	if ( opts.color ) startInfo += genXmlColorSelection( opts.color );
	if ( opts.font_face ) {
		startInfo += '<a:latin typeface="' + opts.font_face + '" pitchFamily="34" ';
		if (opts.lang == "zh-TW"){
			startInfo += 'charset="0"/><a:ea typeface="' + opts.font_face + '" pitchFamily="34" charset="-120"/>';
		}
		else{
			startInfo += 'charset="0"/><a:cs typeface="' + opts.font_face + '" pitchFamily="34" charset="0"/>';
		}
	}
}

Just my small input.
Eddy Kwok

gitbrent pushed a commit that referenced this issue Sep 8, 2017
@gitbrent gitbrent self-assigned this Sep 8, 2017
@gitbrent
Copy link
Owner

gitbrent commented Sep 8, 2017

Hi @eddyclock ,

I've checked in changes to add a new lang option - see if it works correctly now.

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();
//chinese word with chinese font
slide.addText('你好',  { x:0.5, y:1, w:3, font_size:50 , font_face:'微軟正黑體', lang:'zh-TW' });
pptx.save('PptxGenJS-ChineseWord-Font-微軟正黑體');

screen shot 2017-09-07 at 22 38 13

@gitbrent gitbrent changed the title Chinese Word font_face cannot take effective Add new 'lang' text option to enable Chinese Word font_face to take effect Sep 9, 2017
gitbrent pushed a commit that referenced this issue Sep 9, 2017
@gitbrent gitbrent added this to the 1.8.0 milestone Sep 13, 2017
@eddyclock
Copy link
Author

HI @gitbrent

Sorry for long waiting.

It is not correct. I have tried to generate XML file from PowerPoint.

if lang = "zh-TW", I found that there are some key factors as below:

<a:rPr lang="zh-TW" altLang="en-US" ....>
<a:cs typeface ... charset="0"> ...change to <a:ea ... charset="-120">

Hope this can help.
Regards,
Eddy Kwok

gitbrent pushed a commit that referenced this issue Sep 15, 2017
@gitbrent
Copy link
Owner

Hi @eddyclock ,

Thanks for letting me know. Both 'ea' and 'cs' are set to charset="-120" now.

@LawlietNot
Copy link

LawlietNot commented Dec 5, 2017

Hi @gitbrent ,
I found a bug
if set text lang="zh-CN", use office 2007 open fail ,prompt repair and then blank page.
if 2010
image

I do not know pptx xml,so i tried to modify the xml for

<a:latin charset="-122" pitchFamily="34" typeface="微软雅黑"/>
	<a:ea charset="-122" pitchFamily="34" typeface="微软雅黑"/>
	<a:cs charset="-120" pitchFamily="34" typeface="微软雅黑"/>

And at label:ea must be before label:cs,otherwise use office 2007 still is fails.

Is this possible only for Simplified Chinese.

gitbrent pushed a commit that referenced this issue Dec 6, 2017
@gitbrent
Copy link
Owner

gitbrent commented Dec 6, 2017

Hi @LawlietNot,

I've re-ordered the one place where cs was before ea. Let me know if this fixes the issue.

Also, would you mind creating a simple "hello world" PPT using 2007 and attach it? I'd like to see what may be causing these 2007 issues. Thanks!

@eddyclock
Copy link
Author

Hi @LawlietNot
It is fixed and thanks for your help.
Eddy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants