Font Highlight Color

Hi,

We need to handle missing fonts. We are obtaining the list of missing fonts using warning callbacks.

We have a requirement to highlight those portions of our presentation which are being rendered using the missing fonts.

In Aspose.Words, there exists a method “serHighlightColor” in Fonts class.

Do we have any such API in Aspose.Slides? or any way of achieving this?


Thanks
Praneeth

Hi Paraneeth,

I have observed your requirement and like to share that Aspose.Slides does offer to the feature for setting the highlight color for the portion text. Please try using the following sample code on your end to serve the purpose. Please share if I may help you further in this regard.


public static void testHighlight()
{
Presentation p = new Presentation();
IAutoShape autoshape = p.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 300, 150);
autoshape.getTextFrame().getParagraphs().clear();
Paragraph paragraph = new Paragraph();
Portion portion1 = new Portion(“portion 1;”);
portion1.getPortionFormat().getHighlightColor().setColor (Color.YELLOW);
paragraph.getPortions().add(portion1);
Portion portion2 = new Portion(" portion 2");
paragraph.getPortions().add(portion2);
autoshape.getTextFrame().getParagraphs().add(paragraph);
p.save(“D:\Aspose Data\hilightText.pptx”, SaveFormat.Pptx);

}

Many Thanks,

Hi,


Thanks for looking in to this.

We need to set the highlight color for the portion text if its being rendered using the font which belongs to the list of missing font.

In the code snippet given above, where we can set the highlight color on the basis of fonts. First we need to see if the font used is the missing font, if its missing font then we need to highlight those portions of slide which uses this font.

How can we achieve this using Aspose.Slides??

Thanks
Praneeth

Hi Praneeth,

I have observed the requirement shared and regret to share that there is no such feature in Aspose.Slides available that can highlight the missing text with missing font in it. In my previous post, I have shared the mechanism for highlighting portion text. You need to develop your own technique in this regard to highlight the text with missing font inside presentation. Aspose.Slides provides the support for extracting the text from all slides of presentation on portion level. The font properties for text is also set on portion level. You need to traverse through every portion of the each paragraph in shapes inside every slide of presentation. On traversing you extract the font name. On other hand, you maintain a list of fonts that are visible to your JVM and also in your LoadExternalFonts directory. You compare the font belonging to extracted portion text and see if it is available in font list managed by you. If font turn out to be missing in the list, you have found your target and you can highlight that portion. Please visit this documentation link to see how to extract the text from every shape inside presentation slide on portion level and extracting its font. All you need is write a logic on your end to compare the extracted font name in your registered fonts list. For text highlighting, I have already share the sample code with you.

Many Thanks,

Hi,
.
I am using a sample presentation which has following fonts:
1. Calibri
2. Arial

We have configured warning callbacks for font substitution and hence get to know that both the fonts got replaced by some other fonts which are available at machine. This indicates both the fonts are missing.

Our requirement is to highlight those portions of the presentation which are being rendered using the missing fonts.

To achieve this we need to do two things:
1. Get the list of missing fonts: We are generating this list with the help of font substitution warning callbacks

2. For each slide, we need to highlight the portions which are using the missing font.

For this the sample code is given below:

public void performConversion()
{

LoadOptions lo = new LoadOptions();
final HandlePptFontSubstitutionWarning callback = new HandlePptFontSubstitutionWarning();
lo.setWarningCallback(callback);

final PdfOptions options = new PdfOptions();
options.setWarningCallback(callback);

Presentation ppt= new Presentation(“RP_Overview.pptx”, lo);
//rendering presentation to get the list of missing fonts
ppt.save(“RP.pdf”, SaveFormat.Pdf);

final List missingFonts = callback.getMissingFonts();
// If font is missing then do highlighting
if (!missingFonts.isEmpty()) {
ITextFrame[] textFramesPPTX = SlideUtil.getAllTextFrames(ppt, true);
for (int i = 0; i < textFramesPPTX.length; i++) {
for (IParagraph para : textFramesPPTX[i].getParagraphs()) {
for (IPortion port : para.getPortions()) {
if (port.getPortionFormat().getLatinFont() != null) {
String fontName = port.getPortionFormat().getLatinFont().getFontName();
if (missingFonts.contains(fontName)) {
port.getPortionFormat().getHighlightColor().setColor(Color.green);
}
}
}
}
}

}
//Saving the highlighted presentation in PPTX format
ppt.save(“RP_Overview_Highlighted.pptx”, SaveFormat.Pptx);

//Saving the highlighted presentation in PDF format
ppt.save(“RP_Overview_Highlighted.pdf”, SaveFormat.Pdf);

}

public class HandlePptFontSubstitutionWarning implements IWarningCallback {

public HandlePptFontSubstitutionWarning() {
super();
}

/
* Gets the list of missing fonts used in PPTX but not available on machine
* @return list of missing fonts
*/
List getMissingFonts() {
return missingFonts;
}

/

* Aspose.Slides invokes this method when it encounters some issue during presentation saving that might result in loss of formatting or data fidelity.
* @param information the information Aspose provide in case of data fidelity loss.
* @return a constant which indicates operation should be continued.
*/
@Override
public int warning(IWarningInfo information) {
if (information.getWarningType() == WarningType.DataLoss) {
// getting the missing font name out of description message
String fontName = information.getDescription().replace("Font will be substituted from “, “”).split(” to ")[0];
if (!missingFonts.contains(fontName)) {
missingFonts.add(fontName);
}
}
return ReturnAction.Continue;
}

}

From the sample code given above, we are getting two issues:

1. Its only highlighting those portions of presentation which used “Arial” font. It is not highlighting those portions which used “Calibri” font.

2. Highlighted content is seen only when presentation is saved in PPTX format. Not seeing any highlighting done, when presentation is saved in PDF format. We want to see this highlighting effect when presentation is saved in both the formats.


Please help us in resolving all the issues mentioned above.

The sample presentation, presentation saved post highlighting and generated pdf are attached with this mail.

NOTE: We are running code at linux machine (Oracle linux 5 (Intel 64-bit)) and using Aspose.Slides 15.1.0-java.

Thanks
Praneeth

Hi Praneeth,

I have observed your requirement of missing highlight color in generated PDF. I have been been able to observe the issue specified and an issue with ID SLIDESJAVA-34752 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

Now, coming to you first question of Calibri font text not getting highlighted. This is not an issue with Aspose.Slides as the same code is working fine for Arial text. There can be two areas that you need to check on your end. You need to verify that if missingFonts list contains the Calibri font in it and once you find a match, you can replace the text font. The other reason could be that font could be that Calibri font is available in missingFonts list but getLatinFont() font does not have this font. You need to check all of following in portion format for fonts and if any of following contains the Calibri font with condition that your missingFonts list also has Calibri in it. One of them will have the font and you can perform your logic of highlighting text on the basis of this.

1. getEastAsianFont
2. getLatinFont
3. getComplexScriptFont
4. getSymbolFont

Many Thanks,

Hi,


Thanks for looking in to this.

Issue: Calibri font text not getting highlighted.

The missing font list contains Calibri font and I also tried all of following methods and none of them had Calibri.

1. getEastAsianFont
2. getLatinFont
3. getComplexScriptFont
4. getSymbolFont

Thanks
Praneeth

Hi Praneeth,

I have observed the same inquiry by you in another forum thread as well. I have shared my feedback for your kind reference over this forum thread. I request you to please follow this issue in one thread.

Many Thanks,

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


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(1)