Exemplo n.º 1
0
        /// <summary>
        /// Adds a text string to this path.
        /// </summary>
        public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XRect layoutRect,
                              XStringFormat format)
        {
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }

            if (family == null)
            {
                throw new ArgumentNullException("family");
            }

            if (format == null)
            {
                format = XStringFormats.Default;
            }

            if (format.LineAlignment == XLineAlignment.BaseLine && layoutRect.Height != 0)
            {
                throw new InvalidOperationException(
                          "DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0.");
            }

            if (s.Length == 0)
            {
                return;
            }

            XFont font = new XFont(family.Name, emSize, style);

            DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString");
        }
Exemplo n.º 2
0
        // ----- AddString ----------------------------------------------------------------------------

        /// <summary>
        /// Adds a text string to this path.
        /// </summary>
        public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin,
                              XStringFormat format)
        {
            try
            {
                DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString");
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Measure string directly from font data.
        /// </summary>
        public static XSize MeasureString(string text, XFont font, XStringFormat stringFormat)
        {
            XSize size = new XSize();

            OpenTypeDescriptor descriptor = FontDescriptorCache.GetOrCreateDescriptorFor(font) as OpenTypeDescriptor;

            if (descriptor != null)
            {
                // Height is the sum of ascender and descender.
                size.Height = (descriptor.Ascender + descriptor.Descender) * font.Size / font.UnitsPerEm;
                Debug.Assert(descriptor.Ascender > 0);

                bool symbol = descriptor.FontFace.cmap.symbol;
                int  length = text.Length;
                int  width  = 0;
                for (int idx = 0; idx < length; idx++)
                {
                    char ch = text[idx];
                    // HACK: Unclear what to do here.
                    if (ch < 32)
                    {
                        continue;
                    }

                    if (symbol)
                    {
                        // Remap ch for symbol fonts.
                        ch = (char)(ch | (descriptor.FontFace.os2.usFirstCharIndex & 0xFF00));  // @@@ refactor
                        // Used | instead of + because of: http://PdfSharpCore.codeplex.com/workitem/15954
                    }
                    int glyphIndex = descriptor.CharCodeToGlyphIndex(ch);
                    width += descriptor.GlyphIndexToWidth(glyphIndex);
                }
                // What? size.Width = width * font.Size * (font.Italic ? 1 : 1) / descriptor.UnitsPerEm;
                size.Width = width * font.Size / descriptor.UnitsPerEm;

                // Adjust bold simulation.
                if ((font.GlyphTypeface.StyleSimulations & XStyleSimulations.BoldSimulation) == XStyleSimulations.BoldSimulation)
                {
                    // Add 2% of the em-size for each character.
                    // Unsure how to deal with white space. Currently count as regular character.
                    size.Width += length * font.Size * Const.BoldEmphasis;
                }
            }
            Debug.Assert(descriptor != null, "No OpenTypeDescriptor.");
            return(size);
        }