Пример #1
0
        public void GetGlyphsTest()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 7, 0, throwIfOtherPlatform: false);

            using (var txt = new NSTextStorage()) {
                var str = "hello world\n\t";
                txt.SetString(new NSAttributedString(str));
                using (var lm = new NSLayoutManager()) {
                    lm.TextStorage = txt;
                    var glyphs          = new short[str.Length];
                    var props           = new NSGlyphProperty [glyphs.Length];
                    var charIndexBuffer = new nuint [glyphs.Length];
                    var bidiLevelBuffer = new byte [glyphs.Length];
                    lm.GetGlyphs(new NSRange(0, str.Length), glyphs, props, charIndexBuffer, bidiLevelBuffer);
                    Assert.That(glyphs, Is.EqualTo(new short [] { 75, 72, 79, 79, 82, 3, 90, 82, 85, 79, 71, -1, -1 }), "glyphs");
                    Assert.That(props, Is.EqualTo(new NSGlyphProperty [] {
                        0,
                        0,
                        0,
                        0,
                        0,
                        NSGlyphProperty.Elastic,
                        0,
                        0,
                        0,
                        0,
                        0,
                        NSGlyphProperty.ControlCharacter,
                        NSGlyphProperty.ControlCharacter
                    }), "props");
                    Assert.That(charIndexBuffer, Is.EqualTo(new nuint [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }), "charIndexBuffer");
                    Assert.That(bidiLevelBuffer, Is.EqualTo(new byte [str.Length]), "bidiLevelBuffer");
                }
            }

            using (var txt = new NSTextStorage()) {
                var str = "hello world\n\t";
                txt.SetString(new NSAttributedString(str));
                using (var lm = new NSLayoutManager()) {
                    lm.TextStorage = txt;
                    var glyphs          = new short[str.Length];
                    var charIndexBuffer = new nuint [glyphs.Length];
                    var bidiLevelBuffer = new byte [glyphs.Length];
                    lm.GetGlyphs(new NSRange(0, str.Length), glyphs, null, charIndexBuffer, bidiLevelBuffer);
                    Assert.That(glyphs, Is.EqualTo(new short [] { 75, 72, 79, 79, 82, 3, 90, 82, 85, 79, 71, -1, -1 }), "glyphs");

                    Assert.That(charIndexBuffer, Is.EqualTo(new nuint [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }), "charIndexBuffer");
                    Assert.That(bidiLevelBuffer, Is.EqualTo(new byte [str.Length]), "bidiLevelBuffer");
                }
            }
        }
Пример #2
0
		public unsafe nuint GetGlyphs (
			NSRange glyphRange, 
			short[] /* CGGlyph* = CGFontIndex* = unsigned short* */ glyphBuffer,
			NSGlyphProperty[] /* NSGlyphProperty* = nint* */ props,
			nuint[] /* NSUInteger */ charIndexBuffer,
			byte[] /* (unsigned char *) */ bidiLevelBuffer)
		{
			if (glyphBuffer != null && glyphBuffer.Length < glyphRange.Length)
				throw new ArgumentOutOfRangeException (string.Format ("glyphBuffer must have at least {0} elements", glyphRange.Length));

			if (props != null && props.Length < glyphRange.Length)
				throw new ArgumentOutOfRangeException (string.Format ("props must have at least {0} elements", glyphRange.Length));
			
			if (charIndexBuffer != null && charIndexBuffer.Length < glyphRange.Length)
				throw new ArgumentOutOfRangeException (string.Format ("props must have at least {0} elements", glyphRange.Length));

			if (bidiLevelBuffer != null && bidiLevelBuffer.Length < glyphRange.Length)
				throw new ArgumentOutOfRangeException (string.Format ("bidiLevelBuffer must have at least {0} elements", glyphRange.Length));

			fixed (short* glyphs = glyphBuffer) {
				nuint rv;
#if XAMCORE_2_0 && ARCH_32
				// Unified/32: the output array is not the correct size, it needs to be int[], and it's an array of NSGlyphProperty (which is long)
				var tmpArray = new nint [props.Length];
				fixed (nint *properties = tmpArray) {
#else
				// Unified/64 + Classic: the input array is the correct size
				fixed (NSGlyphProperty *properties = props) {
#endif
					fixed (nuint* charIBuffer = charIndexBuffer) {
						fixed (byte* bidi = bidiLevelBuffer) {
							rv = GetGlyphsInternal (glyphRange, (IntPtr) glyphs, (IntPtr) properties, (IntPtr) charIBuffer, (IntPtr) bidi);
						}
					}
				}
#if XAMCORE_2_0 && ARCH_32
				// Marshal back from the tmpArray.
				for (int i = 0; i < props.Length; i++)
					props [i] = (NSGlyphProperty) (long) tmpArray [i];
#endif

				return rv;
			}
		}
Пример #3
0
        public void GetGlyphsTest()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("requires iOS7+");
            }

            using (var txt = new NSTextStorage()) {
                var str = "hello world\n\t";
                txt.SetString(new NSAttributedString(str));
                using (var lm = new NSLayoutManager()) {
                    lm.TextStorage = txt;
                    var glyphs          = new short[str.Length];
                    var props           = new NSGlyphProperty [glyphs.Length];
                    var charIndexBuffer = new nuint [glyphs.Length];
                    var bidiLevelBuffer = new byte [glyphs.Length];
                    lm.GetGlyphs(new NSRange(0, str.Length), glyphs, props, charIndexBuffer, bidiLevelBuffer);
                    Assert.That(glyphs, Is.EqualTo(new short [] { 75, 72, 79, 79, 82, 3, 90, 82, 85, 79, 71, -1, -1 }), "glyphs");
                    Assert.That(props, Is.EqualTo(new NSGlyphProperty [] {
                        0,
                        0,
                        0,
                        0,
                        0,
                        NSGlyphProperty.Elastic,
                        0,
                        0,
                        0,
                        0,
                        0,
                        NSGlyphProperty.ControlCharacter,
                        NSGlyphProperty.ControlCharacter
                    }), "props");
                    Assert.That(charIndexBuffer, Is.EqualTo(new nuint [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }), "charIndexBuffer");
                    Assert.That(bidiLevelBuffer, Is.EqualTo(new byte [str.Length]), "bidiLevelBuffer");
                }
            }
        }