public PDFName RegisterFont(Scryber.Drawing.PDFFont font) { PDFFontResource defn = this.Document.GetFontResource(font, true); defn.RegisterUse(this.Resources, this); return(defn.Name); }
/// <summary> /// All the character widths used /// </summary> /// <param name="chars"></param> /// <param name="frsrc"></param> private void RegisterStringUse(string chars, int startIndex, int endIndex) { //TODO: Confirm this is required, as we are also doing it during the render process. PDFFontResource frsrc = this.CurrentFontResource; if (frsrc.Widths != null) { frsrc.Widths.RegisterGlyphs(chars, startIndex, endIndex); } }
/// <summary> /// Measures a single line of text (no wrapping) and returns the size required, /// and the number of characters fitted into that line. Uses the current font and size. /// </summary> /// <param name="chars"></param> /// <param name="startIndex"></param> /// <param name="available"></param> /// <param name="options"></param> /// <param name="charsfitted"></param> /// <returns></returns> /// <remarks>Uses the TTFFontFile if available, otherwise will default to using the GDI+ measure, /// which is slower but supports postscript fonts</remarks> public PDFSize MeasureString(string chars, int startIndex, PDFSize available, PDFTextRenderOptions options, out int charsfitted) { PDFFontResource frsc = this.CurrentFontResource; PDFUnit fsize = this.CurrentFont.Size; if (null == frsc) { throw new InvalidOperationException("Current font has not be set on the graphics class, so strings cannot be measured"); } PDFFontDefinition defn = frsc.Definition; PDFSize measured; if (defn.CanMeasureStrings) { bool trimtoword = true; if (options.WrapText.HasValue) { if (options.WrapText == WordWrap.NoWrap) { available.Width = new PDFUnit(int.MaxValue, PageUnits.Points); } else if (options.WrapText == WordWrap.Character) { trimtoword = false; } } bool vertical = false; // Not currently supported. //inspect the spacing values - if any are set then we must use them in the calculations bool complexSpacing = false; double?wordSpace = null; double charSpace = Scryber.OpenType.TTFFile.NoCharacterSpace; double hScale = Scryber.OpenType.TTFFile.NoHorizontalScale; if (options.WordSpacing.HasValue) { complexSpacing = true; wordSpace = options.WordSpacing.Value.PointsValue; } if (options.CharacterSpacing.HasValue) { complexSpacing = true; charSpace = options.CharacterSpacing.Value.PointsValue; } if (options.CharacterHScale.HasValue) { complexSpacing = true; hScale = options.CharacterHScale.Value; } if (complexSpacing) { //TODO: Check if we can do this on the widths rather than the ttfile. measured = defn.MeasureStringWidth(chars, startIndex, fsize.PointsValue, available.Width.PointsValue, wordSpace, charSpace, hScale, vertical, trimtoword, out charsfitted); } else { //TODO: Check if we can do this on the widths rather than the ttfile. measured = defn.MeasureStringWidth(chars, startIndex, fsize.PointsValue, available.Width.PointsValue, trimtoword, out charsfitted); } if (charsfitted > 0) { this.RegisterStringUse(chars, startIndex, charsfitted); } } else { throw new NotSupportedException("The font definition cannot measure strings"); //if (startIndex > 0) // chars = chars.Substring(startIndex); //measured = this.MeasureGraphicsString(chars, available, options.WrapText.HasValue ? options.WrapText.Value : WordWrap.Auto, out charsfitted); } return(measured); }