internal void SaveRangeToStream(IDataStream DataStream, TSaveData SaveData, TXlsCellRange CellRange) { int FirstRecord = 0; int RecordCount = 0; CalcIncludedRangeRecords(CellRange, ref FirstRecord, ref RecordCount); if (RecordCount > MaxPageBreaks) { if (SaveData.ThrowExceptionOnTooManyPageBreaks) { XlsMessages.ThrowException(XlsErr.ErrTooManyPageBreaks); } else { RecordCount = MaxPageBreaks; } if (FlexCelTrace.Enabled) { FlexCelTrace.Write(new TXlsTooManyPageBreaksError(XlsMessages.GetString(XlsErr.ErrTooManyPageBreaks), DataStream.FileName)); } } SaveToStreamExt(DataStream, SaveData, FirstRecord, RecordCount); }
private void LoadAllFonts(string FontPath, DirectoryInfo di, string FontExtension, Boolean ErrorIfEmpty) { // Create an array representing the files in the current directory. FileInfo[] fi = di.GetFiles(FontExtension); if (ErrorIfEmpty && fi.Length == 0) { FlxMessages.ThrowException(FlxErr.ErrEmptyFolder, FontPath, FontExtension); } foreach (FileInfo fontFile in fi) { if (FFontFiles.ContainsKey(fontFile.Name)) { continue; } FFontFiles.Add(fontFile.Name, null); try { LoadFont(fontFile.FullName); } catch (Exception ex) { //Invalid font. nothing to do, just continue reading the other fonts. // What we will do is just ignore it here, and throw an exception when (and if) the user actually tries to use this font. if (FlexCelTrace.HasListeners) { FlexCelTrace.Write(new TPdfCorruptFontInFontFolderError(ex.Message, fontFile.FullName)); } } } }
public void AddHyperlink(real x1, real y1, real width, real height, string Url) { try { Canvas.Hyperlink(x1, y1, width, height, Url); } catch (UriFormatException ex) { if (FlexCelTrace.HasListeners) { FlexCelTrace.Write(new TMalformedUrlError(ex.Message, Url)); } } }
internal void SaveAllToStream(IDataStream DataStream, TSaveData SaveData) { if (RealCount() > MaxPageBreaks) { if (SaveData.ThrowExceptionOnTooManyPageBreaks) { XlsMessages.ThrowException(XlsErr.ErrTooManyPageBreaks); } if (FlexCelTrace.Enabled) { FlexCelTrace.Write(new TXlsTooManyPageBreaksError(XlsMessages.GetString(XlsErr.ErrTooManyPageBreaks), DataStream.FileName)); } } SaveToStreamExt(DataStream, SaveData, 0, VirtualCount); }
public static void WriteStringInStream(TPdfStream DataStream, string Text, real FontSize, TPdfFont aFont, ref string LastFont, string EndNewText, string StartNewText2, string EndNewText2, TTracedFonts TracedFonts) { TPdfFont LastFallbackFont = aFont; int StartText = 0; int TLen = Text.Length; for (int i = 0; i <= TLen; i++) { TPdfFont FallbackFont = null; if (i < TLen) { FallbackFont = aFont.Fallback(Text[i], 0); if (FallbackFont == null) { FallbackFont = aFont; } } if (FallbackFont != LastFallbackFont) { WriteSimpleString(DataStream, Text.Substring(StartText, i - StartText), LastFallbackFont, EndNewText); StartText = i; if (FallbackFont != null) { TPdfBaseRecord.Write(DataStream, EndNewText2); FallbackFont.Select(DataStream, FontSize, ref LastFont); if (FlexCelTrace.HasListeners && FallbackFont != aFont && !TracedFonts.ContainsKey(aFont.FontName + ";" + FallbackFont.FontName)) { TracedFonts.Add(aFont.FontName + ";" + FallbackFont.FontName, String.Empty); FlexCelTrace.Write(new TPdfUsedFallbackFontError(FlxMessages.GetString(FlxErr.ErrUsedFallbackFont, aFont.FontName, FallbackFont.FontName), aFont.FontName, FallbackFont.FontName)); } TPdfBaseRecord.Write(DataStream, StartNewText2); LastFallbackFont = FallbackFont; } } } }
internal static TPdfFont CreateInstance(TFontMapping Mapping, Font aFont, bool aUnicode, int aId, TFontEmbed aEmbed, TFontSubset aSubset, bool aCompress, bool aUseKerning, TFontEvents FontEvents, TPdfEmbeddedFontList EmbeddedFontList, TPdfResources aResources) { if (!aUnicode && (Mapping == TFontMapping.ReplaceAllFonts || (Mapping == TFontMapping.ReplaceStandardFonts && IsStandardFont(aFont.Name))) ) { return(new TPdfInternalFont(aFont, aId, aUseKerning, aResources)); } FontStyle AdditionalStyle; TPdfEmbeddedFont EmbeddedData = EmbeddedFontList.Add(aFont, FontEvents, aSubset == TFontSubset.Subset, aUseKerning, out AdditionalStyle); if (AdditionalStyle != FontStyle.Regular) { if (FlexCelTrace.HasListeners) { FlexCelTrace.Write(new TPdfFauxBoldOrItalicsError(FlxMessages.GetString(FlxErr.ErrFauxBoldOrItalic, aFont.Name, GetAdditionalStyleName(AdditionalStyle)), aFont.Name, AdditionalStyle)); } } if (aUnicode) { return(new TPdfUnicodeTrueTypeFont(aFont, aId, aSubset, aCompress, aUseKerning, EmbeddedData, AdditionalStyle, aResources)); } else { bool DoEmbed = aEmbed == TFontEmbed.Embed || EmbeddedData.TrueTypeData.NeedsEmbed(aEmbed); if (FontEvents.OnFontEmbed != null) { FontEmbedEventArgs ae = new FontEmbedEventArgs(aFont, DoEmbed); FontEvents.OnFontEmbed(FontEvents.Sender, ae); DoEmbed = ae.Embed; } return(new TPdfWinAnsiTrueTypeFont(aFont, aId, DoEmbed, aSubset, aCompress, aUseKerning, EmbeddedData, AdditionalStyle, aResources)); } }
public void DrawImage(Image image, RectangleF destRect, RectangleF srcRect, long transparentColor, int brightness, int contrast, int gamma, Color shadowColor, Stream imgData) { if (PointOutside.Check(ref srcRect)) { return; } if (PointOutside.Check(ref destRect)) { return; } if (image.Height <= 0 || image.Width <= 0) { return; } bool ChangedParams = brightness != FlxConsts.DefaultBrightness || contrast != FlxConsts.DefaultContrast || gamma != FlxConsts.DefaultGamma || shadowColor != ColorUtil.Empty; ImageAttributes imgAtt = null; try { if (transparentColor != FlxConsts.NoTransparentColor) { long cl = transparentColor; Color tcl = ColorUtil.FromArgb((int)(cl & 0xFF), (int)((cl & 0xFF00) >> 8), (int)((cl & 0xFF0000) >> 16)); imgAtt = new ImageAttributes(); imgAtt.SetColorKey(tcl, tcl); } if (gamma != FlxConsts.DefaultGamma) { if (imgAtt == null) { imgAtt = new ImageAttributes(); } imgAtt.SetGamma((float)((UInt32)gamma) / 65536f); } if (!ChangedParams && srcRect.Top == 0 && srcRect.Left == 0 && srcRect.Width == image.Width && srcRect.Height == image.Height && imgAtt == null) { bool Retry = false; try { Canvas.DrawImage(image, destRect); //Optimizes the most common case, but there is also an error when cropping metafiles. At least we make sure here this won't have any error on 99% of the cases. } catch (System.Runtime.InteropServices.ExternalException ex) { if (FlexCelTrace.HasListeners) { FlexCelTrace.Write(new TRenderMetafileError(ex.Message)); } Retry = true; //metafiles can raise nasty errors here. } if (Retry) { using (Image bmp = FlgConsts.RasterizeWMF(image)) { Canvas.DrawImage(bmp, destRect); } } } else { Image FinalImage = image; try { if (image.RawFormat.Equals(ImageFormat.Wmf) || image.RawFormat.Equals(ImageFormat.Emf)) { FinalImage = FlgConsts.RasterizeWMF(image); //metafiles do not like cropping or changing attributes. } if (ChangedParams) { if (shadowColor != ColorUtil.Empty) { FlgConsts.MakeImageGray(ref imgAtt, shadowColor); } else { FlgConsts.AdjustImage(ref imgAtt, brightness, contrast); } } PointF[] ImageRect = new PointF[] { new PointF(destRect.Left, destRect.Top), new PointF(destRect.Right, destRect.Top), new PointF(destRect.Left, destRect.Bottom) }; Canvas.DrawImage(FinalImage, ImageRect, srcRect, GraphicsUnit.Pixel, imgAtt); } finally { if (FinalImage != image) { FinalImage.Dispose(); } } } } finally { if (imgAtt != null) { imgAtt.Dispose(); } } }