public override bool AddChar(int code, int FallbackLevel) { bool Result = FTrueTypeData.HasGlyph(code); if (!Result) { TPdfFont Fallbk = FallbackFont(FallbackLevel); if (Fallbk != null) { if (Fallbk.AddChar(code, FallbackLevel + 1)) { return(true); } } } if (Result || FallbackLevel == 0) { int ccode = FTrueTypeData.Glyph(code, true); int newcode = EmbeddedData.GetNewGlyphFromOldGlyph(ccode); UsedChars.Add((char)newcode, FTrueTypeData.GlyphWidth(ccode)); ToUnicodeData.Add(newcode, (int)code); } return(Result); }
public static void UnicodeWrite(TPdfStream DataStream, string Text, TPdfFont aFont) { byte[] Buffer = null; Buffer = aFont.EncodeString(Text); Byte[] Buff2 = TPdfStringRecord.EscapeString(Buffer); DataStream.Write(Buff2); }
internal TPdfFont SelectFont(TPdfStream DataStream, TFontMapping Mapping, Font aFont, string s, TFontEmbed aEmbed, TFontSubset aSubset, bool aUseKerning, ref string LastFont) { TPdfFont Result = GetFont(Mapping, aFont, s, aEmbed, aSubset, aUseKerning); Result.AddString(s); Result.Select(DataStream, aFont.SizeInPoints, ref LastFont); return Result; }
private static void WriteSimpleString(TPdfStream DataStream, string Text, TPdfFont aFont, string EndNewText) { if (Text == null || Text.Length == 0) { return; } Write(DataStream, TPdfTokens.GetString(TPdfToken.OpenString)); UnicodeWrite(DataStream, Text, aFont); Write(DataStream, TPdfTokens.GetString(TPdfToken.CloseString)); TPdfBaseRecord.WriteLine(DataStream, EndNewText); }
protected TPdfFont FallbackFont(int FallbackLevel) { if (FallbackLevel > 0) { return(Resources.CreateFallbackFont(FallbackLevel, FFontStyle, FUseKerning)); } if (FFallbackFont == null) { FFallbackFont = Resources.CreateFallbackFont(FallbackLevel, FFontStyle, FUseKerning); } return(FFallbackFont); }
internal void SaveObjects(TPdfStream DataStream, TXRefSection XRef) { if (Fonts.Count > 0) { foreach (string s in Fonts.OrderedKeys) { TPdfFont pf = ((TPdfFont)Fonts[s]); if (pf.UsedInDoc) pf.WriteFontObject(DataStream, XRef); } } int aCount = Images.Count; for (int i = 0; i < aCount; i++) { Images[i].WriteImageObject(DataStream, XRef); } aCount = HatchPatterns.Count; for (int i = 0; i < aCount; i++) { HatchPatterns[i].WritePatternObject(DataStream, XRef); } if (aCount > 0) { TPdfHatch.WriteColorSpaceObject(DataStream, XRef, PatternColorSpaceId); } aCount = ImageTexturePatterns.Count; for (int i = 0; i < aCount; i++) { ImageTexturePatterns[i].WritePatternObject(DataStream, XRef); } aCount = GradientPatterns.Count; for (int i = 0; i < aCount; i++) { GradientPatterns[i].WritePatternObject(DataStream, XRef); } aCount = Functions.Count; for (int i = 0; i < aCount; i++) { Functions[i].WriteFunctionObject(DataStream, XRef, FCompress); } aCount = GStates.Count; for (int i = 0; i < aCount; i++) { GStates[i].WriteGStateObject(DataStream, XRef); } }
public override TPdfFont Fallback(char c, int FallbackLevel) { if (FTrueTypeData.HasGlyph((int)c)) { return(this); } TPdfFont Fallbk = FallbackFont(FallbackLevel); if (Fallbk != null) { return(Fallbk.Fallback(c, FallbackLevel + 1)); } return(null); }
public override TPdfFont Fallback(char c, int FallbackLevel) { if (CharUtils.IsWin1252((int)c)) { return(this); } TPdfFont Fallbk = FallbackFont(FallbackLevel); if (Fallbk != null) { return(Fallbk.Fallback(c, FallbackLevel + 1)); } return(null); }
public TPdfFont CreateFallbackFont(int FallbackLevel, FontStyle aFontStyle, bool aUseKerning) { if (FFallbackFontList == null || FFallbackFontList.Length <= FallbackLevel) return null; //no fallback. #if (!WPF) using ( #endif Font aFont = new Font(FFallbackFontList[FallbackLevel], 10, aFontStyle) #if (WPF) ; #else ) #endif { TPdfFont Result = GetFont(TFontMapping.DontReplaceFonts, aFont, true, TFontEmbed.Embed, TFontSubset.Subset, aUseKerning); return Result; } }
internal TPdfFont GetFont(TFontMapping Mapping, Font aFont, bool NeedsUnicode, TFontEmbed aEmbed, TFontSubset aSubset, bool aUseKerning) { string key = GetKey(aFont, NeedsUnicode); TPdfFont SearchFont; if (Fonts.ContainsKey(key)) { SearchFont = ((TPdfFont)Fonts[key]); } else { SearchFont = TPdfFont.CreateInstance(Mapping, aFont, NeedsUnicode, Fonts.Count, aEmbed, aSubset, FCompress, aUseKerning, FFontEvents, EmbeddedFontList, this); Fonts.Add(key, SearchFont); } return SearchFont; }
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; } } } }
public override real MeasureString(string s) { real Result = 0; int[] b = new int[s.Length]; bool[] ignore = new bool[s.Length]; for (int i = 0; i < b.Length; i++) { TPdfFont f = Fallback(s[i], 0); if (f != this && f != null) { Result += f.MeasureString(new String(s[i], 1)); ignore[i] = true; b[i] = 0; } else { b[i] = FTrueTypeData.Glyph(s[i], true); } } return(Result + FTrueTypeData.MeasureString(b, ignore)); }
private void SaveFonts(TPdfStream DataStream, TXRefSection XRef) { int aCount = Fonts.Count; if (aCount <= 0) return; TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.FontName)); TDictionaryRecord.BeginDictionary(DataStream); Fonts.CreateOrderedKeys(); foreach (string s in Fonts.Keys) { Fonts.OrderedKeys.Add(s); } Fonts.OrderedKeys.Sort(); //to keep the reference pdfs always the same. foreach (string s in Fonts.OrderedKeys) { TPdfFont pf = ((TPdfFont)Fonts[s]); if (pf.UsedInDoc) pf.WriteFont(DataStream, XRef); } TDictionaryRecord.EndDictionary(DataStream); }
public override bool AddChar(int code, int FallbackLevel) { bool Result = FTrueTypeData.HasGlyph(code); if (!Result) { TPdfFont Fallbk = FallbackFont(FallbackLevel); if (Fallbk != null) { if (Fallbk.AddChar(code, FallbackLevel + 1)) { return(true); } } } if (Result || FallbackLevel == 0) { //characters on winansi are NOT the same than low byte unicode.f.i. char 0x92 is not defined in unicode. byte acode = CharUtils.GetWin1252Bytes_PDF(code); if (FirstChar < 0 || acode < FirstChar) { FirstChar = acode; } if (acode > LastChar) { LastChar = acode; } if (Embed && Subset) { EmbeddedData.AddGlyphFromChar(code); } } return(Result); }
public override real MeasureString(string s) { real Result = 0; //Here we don't have chars > 255, so there are no unicode surrogates. int[] bi = new int[s.Length]; bool[] ignore = new bool[s.Length]; for (int i = 0; i < s.Length; i++) { TPdfFont f = Fallback(s[i], 0); if (f != this && f != null) { Result += f.MeasureString(new String(s[i], 1)); ignore[i] = true; bi[i] = 0; } else { bi[i] = FTrueTypeData.Glyph(s[i], true); //This returns the Glyph for an unicode character, so s[i] is ok. (s is unicode) } } return(Result + FTrueTypeData.MeasureString(bi, ignore)); }