public static void Run() { // ExStart:ManageEmbeddedFonts // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Text(); // Instantiate a Presentation object that represents a presentation file using (Presentation presentation = new Presentation(dataDir + "EmbeddedFonts.pptx")) { // render a slide that contains a text frame that uses embedded "FunSized" presentation.Slides[0].GetThumbnail(new Size(960, 720)).Save(dataDir + "picture1_out.png", ImageFormat.Png); IFontsManager fontsManager = presentation.FontsManager; // get all embedded fonts IFontData[] embeddedFonts = fontsManager.GetEmbeddedFonts(); // find "Calibri" font IFontData funSizedEmbeddedFont = Array.Find(embeddedFonts, delegate(IFontData data) { return(data.FontName == "Calibri"); }); // remove "Calibri" font fontsManager.RemoveEmbeddedFont(funSizedEmbeddedFont); // render the presentation; removed "Calibri" font is replaced to an existing one presentation.Slides[0].GetThumbnail(new Size(960, 720)).Save(dataDir + "picture2_out.png", ImageFormat.Png); // save the presentation without embedded "Calibri" font presentation.Save(dataDir + "WithoutManageEmbeddedFonts_out.ppt", SaveFormat.Ppt); } // ExEnd:ManageEmbeddedFonts }
public static string GetEmbeddedFontUrl(IFontData font, FontStyle style) { if (style == FontStyle.Regular) { return(string.Format("fonts/{0}.ttf", font.FontName)); } return(string.Format("fonts/{0} {1}.ttf", font.FontName, style.ToString())); }
public override void WriteFont( IHtmlGenerator generator, IFontData originalFont, IFontData substitutedFont, string fontStyle, string fontWeight, byte[] fontData) { string fontName = substitutedFont == null ? originalFont.FontName : substitutedFont.FontName; string path = string.Format("{0}.woff", fontName); // some path sanitaze may be needed File.WriteAllBytes(Path.Combine(m_basePath, path), fontData); generator.AddHtml("<style>"); generator.AddHtml("@font-face { "); generator.AddHtml(string.Format("font-family: '{0}'; ", fontName)); generator.AddHtml(string.Format("src: url('{0}')", path)); generator.AddHtml(" }"); generator.AddHtml("</style>"); }
public static string GetTextBulletStyle <T>(IParagraphFormatEffectiveData format, ITextFrameFormatEffectiveData textFrameFormat, bool isTableContent, TemplateContext <T> model) { var firstPortionFormatEffective = (model.Object as Paragraph).Portions[0].PortionFormat.GetEffective(); string fontBoldItalicStyle = GetTextFontItalicStyle(firstPortionFormatEffective); string fontFill = ""; switch (format.Bullet.Type) { case BulletType.Symbol: case BulletType.Numbered: if (format.Bullet.IsBulletHardColor) { fontFill = string.Format("color: {0};", ColorHelper.GetRrbaColorString(format.Bullet.FillFormat.SolidFillColor)); } else { fontFill = FillHelper.GetFillStyle(firstPortionFormatEffective.FillFormat, model); if (fontFill.StartsWith("background-color: ")) { // fix for solid fill fontFill = fontFill.Replace("background-color: ", "color: "); } else { // additional css for non-solid fills fontFill += " -webkit-text-fill-color: transparent; -webkit-background-clip: text;"; } } break; case BulletType.Picture: // picture bullet break; } IFontData bulletFont = firstPortionFormatEffective.LatinFont; if (format.Bullet.IsBulletHardFont && format.Bullet.Type != BulletType.Numbered) { bulletFont = format.Bullet.Font; } var shadowFix = (textFrameFormat.TextVerticalType == TextVerticalType.Vertical || textFrameFormat.TextVerticalType == TextVerticalType.Vertical270 ? -1 : 1) * (isTableContent ? 0.5f : 1); string outerShadowStyle = ""; if (firstPortionFormatEffective.EffectFormat.OuterShadowEffect != null) { outerShadowStyle = string.Format("text-shadow: {0}px {1}px {2}px {3};", shadowFix * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Distance * Math.Cos((Math.PI / 180) * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Direction), shadowFix * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Distance * Math.Sin((Math.PI / 180) * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Direction), firstPortionFormatEffective.EffectFormat.OuterShadowEffect.BlurRadius, ColorHelper.GetRrbaColorString(firstPortionFormatEffective.EffectFormat.OuterShadowEffect.ShadowColor)); } string fontHeightStyle = string.Format("font-size: {0}px;", format.Bullet.Height * firstPortionFormatEffective.FontHeight / 100); string fontFamilyStyle = string.Format("font-family: {0};", bulletFont); return(string.Join(" ", fontBoldItalicStyle, fontFill, outerShadowStyle, fontHeightStyle, fontFamilyStyle)); }