We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PPTX font name issue

Hi,

I get a strange font name from pptx api. I am using following code:

PresentationEx presentation = new PresentationEx(“d:/pptx/links-test.pptx”);

SlideEx slide = presentation.getSlides().get(0);

ShapesEx shapes = slide.getShapes();

ShapeEx shape = shapes.get(1);

AutoShapeEx ashape = (AutoShapeEx) shape;

TextFrameEx tf = ashape.getTextFrame();

if(tf != null) {
ParagraphsEx paragraphs = tf.getParagraphs();

ParagraphEx paragraph = paragraphs.get(1);

PortionsEx portions = paragraph.getPortions();

PortionEx portion = portions.get(0);

System.out.println(portion.getText());
System.out.println(portion.getLatinFont().getFontName());
}

links-test.pptx is in attachment.

Why is this happening?

Thanks,
Zeljko

Hi Zeljko,

Thanks for your interest in Aspose.Slides.

I have observed the code snippet shared by you. The presentation file that you have shared is actually a PPT and you cannot access a PPT file using a code snippet that is meant to be used for PPTX files. I have converted the PPT file to PPTX using MS PowerPoint 2007. In order to get the font name from please use the following code line.

System.out.println(portion.getRawLatinFont().getFontName());

There is one more thing that for some of fonts exception is thrown. This issue is under investigation and an issue with ID 11698 has already been created in our issue tracking system for its resolution. This thread has also been linked with the issue, so that you may be automatically notified, once the issue is resolved.

Thanks and Regards,

Hi,

This is helpful, but what is difference between PortionEx.getLatinFont() and PortionEx.getRawLatinFont(), also when I should use PortionEx.getEastAsianFont(), PoritonEx.getComplexScriptFont(), PortionEx.getSymbolFont() or PortionEx.getRawEastAsianFont(), PoritonEx.getRawComplexScriptFont(), PortionEx.getRawSymbolFont().

Thanks,
Zeljko

Hi,

Can you help me?

Zeljko

Hi Zeljko,

I am sorry for the delayed response.

The function calls that you have mentioned returns "+mn-lt ", which is a reference to theme’s font scheme. +mn means minor font, +mj means major font. lt means Latin font, ea means Eastern Asian, cs means Complex Script.

In order to get actual minor Latin font name from a theme, user should call:

getTheme().getFontScheme().getMinor().getLatinFont().getFontName()

Moreover, Portion.getRawLatinFont() , as any other Raw-properties returns FontDataEx specifically set for this portion. In most cases this will return null , which means there is no font set and renderer should use other font, inherited from ParagraphEx’s default character properties or from some level of text styles. Portion.getLatinFont() does all inheritance work. Hope it answers your query.

Thanks and Regards,

Hi,

Can you tell me when I should use Latin, EastAsia or Complex font? How I can find getTheme() method and what is minor and major font name? I don’t know type of font used in PPTX Presentation.

I am confused in PPT api it was very easy, at any time I can get font index using Portion.getFontIndex(), and at Presentation level I can get all fonts used in Presentation using Presentation.getFonts() which returns collection of fonts. Portion.getFontIndex() returns index of font which is same as index in collection of fonts from Presentation level.

Thanks,
Zeljko

Hi,

Can you provide me Java code sample which will show me how I can get font name, font size, is font italic, is font bold, is font underlined? That code sample should work with any PPTX presentation.

Thanks,
Zeljko

Hi Zeljko,

We are greatly sorry for the delayed response.

I have discussed the issue in detail with our development team.

Firsts of all, the getTheme() is a method from SlideEx class. Answering to second part of your question that a portion has four fonts properties, LatinFont (font for characters from almost all languages), EastAsianFont (hieroglyphs), ComplexScriptFont (font for languages with right-to-left writing direction) and SymbolFont (math symbols, pictograms and so on). When rendering, font is selected, depending on type of character to draw. Minor font is a default for a regular text and major font is a default font for headers, titles and so on. Please use the following code snippet for getting the font name for a portion.

PresentationEx Pres=new PresentationEx("D:\\ppt\\Test.pptx");

SlideEx Slide = presentation.getSlides().get(0);
ThemeEx Theme = slide.getTheme();

ShapesEx Shapes = Slide.getShapes();
ShapeEx Shape = Shapes.get(1);
AutoShapeEx aShape = (AutoShapeEx) Shape;

TextFrameEx tfText = aShape.getTextFrame();

if(tfText != null) {

//Fetching portion text from textframe paragraph

ParagraphEx pPara = tfText.getParagraphs().get(0);
PortionEx pPort = pPara.getPortions().get(0);

//Getting Font name

String fontname = getThemeFontName(pPort .getLatinFont().getFontName(), Theme);

}

static String getThemeFontName(String fontName, ThemeEx theme)
{
if(fontName == null || theme == null || fontName.length() != 6 || fontName.charAt(0) != '+')
return fontName;
FontsEx fonts = null;
if (fontName.startsWith("+mn-"))
fonts = theme.getFontScheme().getMinor();
else if (fontName.startsWith("+mj-"))
fonts = theme.getFontScheme().getMajor();
else return fontName;
if (fontName.endsWith("lt"))
return fonts.getLatinFont().getFontName();
else if (fontName.endsWith("ea"))
return fonts.getEastAsianFont().getFontName();
else if (fontName.endsWith("cs"))
return fonts.getComplexScriptFont().getFontName();
else return fontName;
}
Hopefully it will resolve your query now.
Thanks and Regards,

The issues you have found earlier (filed as 11698) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(7)