Exemple #1
0
        [Culture("en")]          // fails for some cultures, e.g. ar-AE
        public void DrawString_7()
        {
            nfloat actualFontSize = 12;
            var    f = UIFont.BoldSystemFontOfSize(actualFontSize);

            try {
                using (NSString s = new NSString("s")) {
                    var size = s.DrawString(CGPoint.Empty, 20, f, 6, ref actualFontSize, UILineBreakMode.MiddleTruncation, UIBaselineAdjustment.None);
                    Assert.That(actualFontSize, Is.EqualTo((nfloat)12), "actualFontSize");
                    Assert.That(size.Width, Is.InRange((nfloat)6f, (nfloat)7f), "Width");
                    Assert.That(size.Height, Is.InRange((nfloat)14f, (nfloat)15f), "Height");
                }
                using (NSString s = new NSString("saterlipopette")) {
                    var size = s.DrawString(CGPoint.Empty, 20, f, 6, ref actualFontSize, UILineBreakMode.MiddleTruncation, UIBaselineAdjustment.None);
                    Assert.That(actualFontSize, Is.EqualTo((nfloat)6), "actualFontSize-2");
                    Assert.That(size.Width, Is.InRange((nfloat)17f, (nfloat)19f), "Width-2");
                    Assert.That(size.Height, Is.InRange((nfloat)7f, (nfloat)8f), "Height-2");
                }
            } catch {
                Console.WriteLine("DrawString_7: actualFontSize: {0} font: {1}", actualFontSize, f);
                throw;
            }
        }
Exemple #2
0
        [Culture("en")]          // fails for some cultures, e.g. ar-AE
        public void StringSize_5()
        {
            nfloat actualFontSize = 12;
            var    f = UIFont.BoldSystemFontOfSize(actualFontSize);

            try {
                using (NSString s = new NSString("s")) {
                    var size = s.StringSize(f, 6, ref actualFontSize, 10, UILineBreakMode.MiddleTruncation);
                    Assert.That(actualFontSize, Is.EqualTo((nfloat)12), "actualFontSize");
                    Assert.That(size.Width, Is.InRange((nfloat)6f, (nfloat)7f), "Width");
                    Assert.That(size.Height, Is.InRange((nfloat)14f, (nfloat)15f), "Height");
                }
                using (NSString s = new NSString("saterlipopette")) {
                    var size = s.StringSize(f, 6, ref actualFontSize, 10, UILineBreakMode.MiddleTruncation);
                    Assert.That(actualFontSize, Is.EqualTo((nfloat)6), "actualFontSize-2");
                    Assert.That(size.Width, Is.InRange((nfloat)5f, (nfloat)10f), "Width-2");
                    Assert.That(size.Height, Is.InRange((nfloat)14f, (nfloat)15f), "Height-2");
                }
            } catch {
                Console.WriteLine("StringSize_5: actualFontSize: {0} font: {1}", actualFontSize, f);
                throw;
            }
        }
 public unsafe void AppendPathWithGlyphs(uint[] glyphs, NSFont font)
 {
     if (glyphs == null)
         throw new ArgumentNullException("glyphs"); }
        static internal NSDictionary ToDictionary(
            NSFont font,
            NSColor foregroundColor,
            NSColor backgroundColor,
            NSColor strokeColor,
            NSColor underlineColor,
            NSColor strikethroughColor,
            NSUnderlineStyle underlineStyle,
            NSUnderlineStyle strikethroughStyle,
            NSParagraphStyle paragraphStyle,
            float strokeWidth,
            NSShadow shadow,
            NSUrl link,
            bool superscript,
            NSTextAttachment attachment,
            NSLigatureType ligature,
            float baselineOffset,
            float kerningAdjustment,
            float obliqueness,
            float expansion,
            NSCursor cursor,
            string toolTip,
            int characterShape,
            NSGlyphInfo glyphInfo,
            NSArray writingDirection,
            bool markedClauseSegment,
            NSTextLayoutOrientation verticalGlyphForm,
            NSTextAlternatives textAlternatives,
            NSSpellingState spellingState)
        {
            var attr = new NSStringAttributes();

            if (font != null)
            {
                attr.Font = font;
            }

            if (paragraphStyle != null)
            {
                attr.ParagraphStyle = paragraphStyle;
            }

            if (foregroundColor != null)
            {
                attr.ForegroundColor = foregroundColor;
            }

            if (underlineStyle != NSUnderlineStyle.None)
            {
                attr.UnderlineStyle = (int?)underlineStyle;
            }

            if (superscript)
            {
                attr.Superscript = true;
            }

            if (backgroundColor != null)
            {
                attr.BackgroundColor = backgroundColor;
            }

            if (attachment != null)
            {
                attr.Attachment = attachment;
            }

            if (ligature != NSLigatureType.Default)
            {
                attr.Ligature = ligature;
            }

            if (baselineOffset != 0)
            {
                attr.BaselineOffset = baselineOffset;
            }

            if (kerningAdjustment != 0)
            {
                attr.KerningAdjustment = kerningAdjustment;
            }

            if (link != null)
            {
                attr.Link = link;
            }

            if (strokeWidth != 0)
            {
                attr.StrokeWidth = strokeWidth;
            }

            if (strokeColor != null)
            {
                attr.StrokeColor = strokeColor;
            }

            if (underlineColor != null)
            {
                attr.UnderlineColor = underlineColor;
            }

            if (strikethroughStyle != NSUnderlineStyle.None)
            {
                attr.StrikethroughStyle = (int?)strikethroughStyle;
            }

            if (strikethroughColor != null)
            {
                attr.StrikethroughColor = strikethroughColor;
            }

            if (shadow != null)
            {
                attr.Shadow = shadow;
            }

            if (obliqueness != 0)
            {
                attr.Obliqueness = obliqueness;
            }

            if (expansion != 0)
            {
                attr.Expansion = expansion;
            }

            if (cursor != null)
            {
                attr.Cursor = cursor;
            }

            if (toolTip != null)
            {
                attr.ToolTip = toolTip;
            }

            if (characterShape != 0)
            {
                attr.CharacterShape = 0;
            }

            if (glyphInfo != null)
            {
                attr.GlyphInfo = glyphInfo;
            }

            if (writingDirection != null)
            {
                attr.WritingDirection = writingDirection;
            }

            if (markedClauseSegment)
            {
                attr.MarkedClauseSegment = true;
            }

            if (verticalGlyphForm != NSTextLayoutOrientation.Horizontal)
            {
                attr.VerticalGlyphForm = verticalGlyphForm;
            }

            if (textAlternatives != null)
            {
                attr.TextAlternatives = textAlternatives;
            }

            if (spellingState != NSSpellingState.None)
            {
                attr.SpellingState = spellingState;
            }

            var dict = attr.Dictionary;

            return(dict.Count == 0 ? null : dict);
        }