コード例 #1
0
ファイル: XRect.cs プロジェクト: MykolaKovalchuk/SAE5
 /// <summary>
 /// Initializes a new instance of the XRect class.
 /// </summary>
 public XRect(XPoint location, XSize size)
 {
     if (size.IsEmpty)
     {
         this = s_empty;
     }
     else
     {
         _x      = location.X;
         _y      = location.Y;
         _width  = size.Width;
         _height = size.Height;
     }
 }
コード例 #2
0
ファイル: FontHelper.cs プロジェクト: MykolaKovalchuk/SAE5
        /// <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://pdfsharp.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);
        }
コード例 #3
0
ファイル: XRect.cs プロジェクト: MykolaKovalchuk/SAE5
 /// <summary>
 /// Returns the rectangle that results from expanding the specified rectangle by the specified Size, in all directions.
 /// </summary>
 public static XRect Inflate(XRect rect, XSize size)
 {
     rect.Inflate(size.Width, size.Height);
     return(rect);
 }
コード例 #4
0
ファイル: XRect.cs プロジェクト: MykolaKovalchuk/SAE5
 /// <summary>
 /// Expands the rectangle by using the specified Size, in all directions.
 /// </summary>
 public void Inflate(XSize size)
 {
     Inflate(size.Width, size.Height);
 }
コード例 #5
0
ファイル: XSize.cs プロジェクト: MykolaKovalchuk/SAE5
 static XSize()
 {
     s_empty = CreateEmptySize();
 }
コード例 #6
0
ファイル: XSize.cs プロジェクト: MykolaKovalchuk/SAE5
 /// <summary>
 /// Indicates whether this instance and a specified size are equal.
 /// </summary>
 public bool Equals(XSize value)
 {
     return(Equals(this, value));
 }