Exemple #1
0
 public CodePointVM(CodePoint cp, IEnumerable <CodePoint> similar, IEnumerable <CodePoint> radicals, string romaji)
 {
     CodePoint     = cp;
     Similar       = similar;
     this.radicals = radicals?.Select(r => r.ToString()).ToList() ?? Enumerable.Empty <string>();
     this.romaji   = romaji;
 }
        public IEnumerable <StyleCopCodeIssue> GetCodeIssues(
            ISourceCode sourceCode,
            Func <ElementTypeFilter, IEnumerable <IElement> > enumerate,
            Violation violation,
            CsElement csElement)
        {
            CodePoint startPoint = null;
            CodePoint endPoint   = null;
            bool      emptyLine  = true;

            foreach (var token in csElement.ElementTokens.Flatten().Where(x => x.LineNumber == violation.Line))
            {
                if (startPoint == null)
                {
                    startPoint = token.Location.StartPoint;
                    endPoint   = token.Location.EndPoint;
                    emptyLine  = token.CsTokenType == CsTokenType.WhiteSpace || token.CsTokenType == CsTokenType.EndOfLine;
                }

                if (token.CsTokenType != CsTokenType.WhiteSpace && token.CsTokenType != CsTokenType.EndOfLine)
                {
                    if (emptyLine)
                    {
                        startPoint = token.Location.StartPoint;
                        emptyLine  = false;
                    }

                    endPoint = token.Location.EndPoint;
                }
                else if (token.CsTokenType == CsTokenType.EndOfLine)
                {
                    yield return(new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2)));
                }
            }
        }
        static IEnumerable <CodePoint> GetCodePoints(string s)
        {
            var bytes = UTF32.GetBytes(s);

            for (int i = 0; i < bytes.Length; i += 4)
            {
                var cp = new CodePoint();

                var utf32 = new byte[4];
                Array.Copy(bytes, i, utf32, 0, 4);
                cp.utf32 = utf32;

                cp.value = (utf32[0] << 0)
                           | (utf32[1] << 8)
                           | (utf32[2] << 16)
                           | (utf32[3] << 24);

                var decoded = UTF32.GetString(utf32);
                cp.@char = decoded;
                cp.utf16 = Unicode.GetBytes(decoded);
                cp.utf8  = UTF8.GetBytes(decoded);

                yield return(cp);
            }
        }
Exemple #4
0
 public int Lookup(CodePoint codePoint)
 {
     int index;
     if (table.TryGetValue(codePoint, out index))
         return index;
     return -1;
 }
Exemple #5
0
        public static GlyphShapingClass GetGlyphShapingClass(FontMetrics fontMetrics, ushort glyphId, GlyphShapingData shapingData)
        {
            bool   isMark;
            bool   isBase;
            bool   isLigature;
            ushort markAttachmentType = 0;

            if (fontMetrics.TryGetGlyphClass(glyphId, out GlyphClassDef? glyphClass))
            {
                isMark     = glyphClass == GlyphClassDef.MarkGlyph;
                isBase     = glyphClass == GlyphClassDef.BaseGlyph;
                isLigature = glyphClass == GlyphClassDef.LigatureGlyph;
                if (fontMetrics.TryGetMarkAttachmentClass(glyphId, out GlyphClassDef? markAttachmentClass))
                {
                    markAttachmentType = (ushort)markAttachmentClass;
                }
            }
            else
            {
                // TODO: We may have to store each codepoint. FontKit checks all.
                isMark     = CodePoint.IsMark(shapingData.CodePoint);
                isBase     = !isMark;
                isLigature = shapingData.CodePointCount > 1;
            }

            return(new GlyphShapingClass(isMark, isBase, isLigature, markAttachmentType));
        }
Exemple #6
0
 protected override void onChar(CodePoint cp)
 {
     if (crow.ProcessKeyPress(cp.ToChar()))
     {
         return;
     }
 }
Exemple #7
0
 public UInt16Parameter(
     CodePoint codePoint,
     UInt16 value)
 {
     CodePoint = codePoint;
     Value     = value;
 }
 /// <summary>
 /// Gets the glyphs for the given codepoint.
 /// </summary>
 /// <param name="codePoint">The code point of the character.</param>
 /// <param name="support">Options for enabling color font support during layout and rendering.</param>
 /// <returns>Returns the glyph</returns>
 public IEnumerable <Glyph> GetGlyphs(CodePoint codePoint, ColorFontSupport support)
 {
     foreach (GlyphMetrics metrics in this.FontMetrics.GetGlyphMetrics(codePoint, support))
     {
         yield return(new(metrics, this.Size));
     }
 }
Exemple #9
0
        static public Range GetAllByChar(CodePoint cp)
        {
            int b, e;

            _charIdx.EqualRange(cp, out b, out e);
            return(new Range((ushort)b, (ushort)e));
        }
Exemple #10
0
        public static bool TryDecode(ushort[] buffer, ref int index, out CodePoint codePoint)
        {
            codePoint = default(CodePoint);

            if (index >= buffer.Length) return false;

            uint x = buffer[index++];

            if ((x & 0b1111_1100_0000_0000) == 0b1101_1000_0000_0000)
            {
                var code = (x & 0b0011_1111_1111) + 0b0100_0000;
                if (index >= buffer.Length) return false;
                x = buffer[index++];
                if ((x & 0b1111_1100_0000_0000) != 0b1101_1100_0000_0000) return false;
                code = (code << 10) | (x & 0b0011_1111_1111);

                codePoint = new CodePoint(code);
                return true;
            }
            else
            {
                codePoint = new CodePoint(x);
                return true;
            }
        }
        public static void Main()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            CodePoint.LoadUnicodeData();

            const int BUFFER_SIZE = 500 * 1024;

            using (StreamWriter writer = new StreamWriter(File.Create("GeneratedDILSupportFunctions.js", BUFFER_SIZE, FileOptions.SequentialScan), Encoding.UTF8, BUFFER_SIZE))
            {
                const string GENERATEDCODE_START = "/**** GENERATED CODE STARTS HERE ****/";
                const string GENERATEDCODE_END   = "/**** GENERATED CODE ENDS HERE ****/";

                writer.AutoFlush = false;

                writer.WriteLine(writer.NewLine);

                writer.WriteLine(GENERATEDCODE_START);
                GeneratePatterns(writer);
                writer.WriteLine(GENERATEDCODE_END);

                writer.WriteLine(writer.NewLine);
                writer.WriteLine(writer.NewLine);

                writer.WriteLine(GENERATEDCODE_START);
                GenerateUppercaseMappings(writer);
                writer.WriteLine(GENERATEDCODE_END);
            }
        }
Exemple #12
0
        public void GlyphMetricsMatchesReference_WithWoff1format()
        {
            // Compared to EveryFonts TTFDump metrics
            // https://everythingfonts.com/ttfdump
            var        collection = new FontCollection();
            FontFamily family     = collection.Add(TestFonts.OpenSansFileWoff1);
            Font       font       = family.CreateFont(12);

            var          codePoint     = new CodePoint('A');
            GlyphMetrics glyphMetrics  = font.FontMetrics.GetGlyphMetrics(codePoint, ColorFontSupport.None).First();
            GlyphMetrics glyphMetrics1 = font.GetGlyphs(codePoint, ColorFontSupport.None).First().GlyphMetrics;

            Assert.Equal(glyphMetrics, glyphMetrics1);

            Assert.Equal(codePoint, glyphMetrics.CodePoint);
            Assert.Equal(font.FontMetrics.UnitsPerEm, glyphMetrics.UnitsPerEm);
            Assert.Equal(glyphMetrics.UnitsPerEm * 72F, glyphMetrics.ScaleFactor);
            Assert.Equal(1295, glyphMetrics.AdvanceWidth);
            Assert.Equal(2789, glyphMetrics.AdvanceHeight);
            Assert.Equal(1293, glyphMetrics.Width);
            Assert.Equal(1468, glyphMetrics.Height);
            Assert.Equal(0, glyphMetrics.LeftSideBearing);
            Assert.Equal(721, glyphMetrics.TopSideBearing);
            Assert.Equal(GlyphType.Standard, glyphMetrics.GlyphType);
        }
Exemple #13
0
        public void GlyphMetricsVerticalMatchesReference()
        {
            // Compared to EveryFonts TTFDump metrics
            // https://everythingfonts.com/ttfdump
            var        collection = new FontCollection();
            FontFamily family     = collection.Add(TestFonts.NotoSansSCThinFile);
            Font       font       = family.CreateFont(12);

            var          codePoint     = new CodePoint('A');
            GlyphMetrics glyphMetrics  = font.FontMetrics.GetGlyphMetrics(codePoint, ColorFontSupport.None).First();
            GlyphMetrics glyphMetrics1 = font.GetGlyphs(codePoint, ColorFontSupport.None).First().GlyphMetrics;

            Assert.Equal(glyphMetrics, glyphMetrics1);

            // Position 0.
            Assert.Equal(codePoint, glyphMetrics.CodePoint);
            Assert.Equal(font.FontMetrics.UnitsPerEm, glyphMetrics.UnitsPerEm);
            Assert.Equal(glyphMetrics.UnitsPerEm * 72F, glyphMetrics.ScaleFactor);
            Assert.Equal(364, glyphMetrics.AdvanceWidth);
            Assert.Equal(1000, glyphMetrics.AdvanceHeight);
            Assert.Equal(265, glyphMetrics.Width);
            Assert.Equal(666, glyphMetrics.Height);
            Assert.Equal(33, glyphMetrics.LeftSideBearing);
            Assert.Equal(134, glyphMetrics.TopSideBearing);
            Assert.Equal(GlyphType.Fallback, glyphMetrics.GlyphType);
        }
Exemple #14
0
 public UInt8Parameter(
     CodePoint codePoint,
     Byte value)
 {
     CodePoint = codePoint;
     Value     = value;
 }
Exemple #15
0
        static public IEnumerable <Rime19> GetAllByChar(CodePoint cp)
        {
            var    range = ESyllable.GetAllByChar(cp);
            Rime19 last  = new Rime19 {
                _i = 0xff
            };

            for (int i = 0; i < range.Count; ++i)
            {
                var syl  = range[i];
                var er   = ESection.GetByRime(syl.Final.Index, syl.Tone);
                var fork = _erTo19[er.Index];
                var curr = new Rime19 {
                    _i = (fork.First == 30 /*泰*/ && !syl.Final.Rounded) ? fork.Second : fork.First
                };

                if (!curr.Equals(last))
                {
                    yield return(last = curr);

                    if (fork.Count == 2 && (er.Title == '佳' || er.Title == '卦') && _jias.Contains(cp))
                    {
                        yield return(last = new Rime19 {
                            _i = fork.Second
                        });
                    }
                }
            }
        }
Exemple #16
0
        static IEnumerable<CodePoint> GetCodePoints(string s)
        {
            var bytes = UTF32.GetBytes(s);

            for (int i = 0; i < bytes.Length; i += 4)
            {
                var cp = new CodePoint();

                var utf32 = new byte[4];
                Array.Copy(bytes, i, utf32, 0, 4);
                cp.utf32 = utf32;

                cp.value = (utf32[0] << 0)
                    | (utf32[1] << 8)
                    | (utf32[2] << 16)
                    | (utf32[3] << 24);

                var decoded = UTF32.GetString(utf32);
                cp.@char = decoded;
                cp.utf16 = Unicode.GetBytes(decoded);
                cp.utf8 = UTF8.GetBytes(decoded);

                yield return cp;
            }
        }
Exemple #17
0
 public BytesParameter(
     CodePoint codePoint,
     Byte[] value)
 {
     CodePoint = codePoint;
     Value     = value;
 }
Exemple #18
0
 public CompositeCommand(
     CodePoint codePoint,
     params IDrdaMessage[] parameters)
 {
     CodePoint   = codePoint;
     _parameters = parameters;
 }
        public IEnumerable <StyleCopCodeIssue> GetCodeIssues(
            ISourceCode sourceCode,
            Func <ElementTypeFilter, IEnumerable <IElement> > enumerate,
            Violation violation,
            CsElement csElement)
        {
            CodePoint startPoint = null;
            CodePoint endPoint   = null;

            foreach (var token in from token in csElement.ElementTokens
                     where token.LineNumber >= violation.Line
                     select token)
            {
                if (token.CsTokenType == CsTokenType.UsingDirective || token.CsTokenType == CsTokenType.Using)
                {
                    startPoint = token.Location.StartPoint;
                    continue;
                }

                if (token.CsTokenType == CsTokenType.Semicolon)
                {
                    endPoint = token.Location.EndPoint;
                }

                if (startPoint != null && endPoint != null)
                {
                    var sourceRange = new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2);
                    yield return(new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange));
                }
            }
        }
Exemple #20
0
        private void Init(IEnumerable <KanaCharacter> kana)
        {
            int x = 0;
            int y = 0;

            foreach (var k in kana)
            {
                if (k != null)
                {
                    Kana.Add(new KanaVM(this, CodePoint.FromString(k.Kana), k.Romaji, x, y));
                }
                else
                {
                    Kana.Add(new KanaVM(this, null, null, x, y));
                }

                x++;
                if (x == 5)
                {
                    x = 0;
                    y++;
                }
            }

            Width  = x == 0 ? y : y + 1;
            Height = 5;

            var contents = Kana.OrderBy(k => k.X * Width + -k.Y).ToList();

            Kana.Clear();
            Kana.AddRange(contents);
        }
Exemple #21
0
        public static bool TryDecode(byte[] buffer, ref int index, out CodePoint codePoint)
        {
            codePoint = default(CodePoint);

            if (index >= buffer.Length)
            {
                return(false);
            }

            uint code = buffer[index];

            if (code < 0b1100_0000)
            {
                // ASCII 文字
                codePoint = new CodePoint(code);
                ++index;
                return(true);
            }
            if (code < 0b1110_0000)
            {
                // 2バイト文字
                if (index + 1 >= buffer.Length)
                {
                    return(false);
                }
                code &= 0b1_1111;
                code  = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
                ++index;
                codePoint = new CodePoint(code);
                return(true);
            }
            if (code < 0b1111_0000)
            {
                // 3バイト文字
                if (index + 2 >= buffer.Length)
                {
                    return(false);
                }
                code &= 0b1111;
                code  = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
                code  = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
                ++index;
                codePoint = new CodePoint(code);
                return(true);
            }

            // 4バイト文字
            if (index + 3 >= buffer.Length)
            {
                return(false);
            }
            code &= 0b0111;
            code  = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
            code  = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
            code  = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
            ++index;
            codePoint = new CodePoint(code);
            return(true);
        }
Exemple #22
0
 public static bool IsOblique(CodePoint cp)
 {
     var range = ESyllable.GetAllByChar(cp);
     for (int i = 0; i < range.Count; i++)
         if (range[i].Tone != Tone.Level)
             return true;
     return false;
 }
Exemple #23
0
 public UInt16Parameter(
     DrdaStreamReader reader,
     CodePoint codePoint)
     : this(
         codePoint,
         reader.ReadUInt16())
 {
 }
Exemple #24
0
 protected override void onChar(CodePoint cp)
 {
     if (iFace.OnKeyPress(cp.ToChar()))
     {
         return;
     }
     base.onChar(cp);
 }
 public void CodePointIsWhiteSpaceBmp()
 {
     for (uint i = 0x7Fu + 1u; i <= 0xFFFFu; i++)
     {
         Assert.True(UnicodeUtility.IsBmpCodePoint(i));
         Assert.Equal(CodePoint.IsWhiteSpace(new CodePoint(i)), char.IsWhiteSpace((char)i));
     }
 }
 public void CodePointIsWhiteSpaceAscii()
 {
     for (uint i = 0; i <= 0x7Fu; i++)
     {
         Assert.True(UnicodeUtility.IsAsciiCodePoint(i));
         Assert.Equal(CodePoint.IsWhiteSpace(new CodePoint(i)), char.IsWhiteSpace((char)i));
     }
 }
Exemple #27
0
 public KanaVM(KanaBoardVM boardVM, CodePoint codePoint, string romaji, int x, int y)
 {
     this.boardVM = boardVM;
     CodePoint    = codePoint;
     Romaji       = romaji;
     X            = x;
     Y            = y;
 }
Exemple #28
0
 public CompositeCommand(
     DrdaStreamReader reader,
     UInt32 sizeWithoutHeader,
     CodePoint codePoint)
     : this(
         codePoint,
         ReadParameters(reader, sizeWithoutHeader).ToArray())
 {
 }
Exemple #29
0
 /// <summary>
 /// Any flags associated with this code point, such as "is white space?"
 /// </summary>
 /// <remarks>
 /// See https://www.unicode.org/reports/tr44/#PropList.txt.
 /// </remarks>
 public static CodePointFlags GetFlags(this CodePoint codePoint)
 {
     if (UnicodeData.CurrentData.PropListData.TryGetValue(codePoint.Value, out CodePointFlags flags))
     {
         return(flags);
     }
     else
     {
         return(default);                // default is "no flags"
Exemple #30
0
        public override CharClassSpec AsCharClass()
        {
            if (Value.Length != 1 || !(Value.Length == 2 && char.IsHighSurrogate(Value[0])))
            {
                return(null);
            }

            return(new CharClassSpec(new InversionListCodePointSet(CodePoint.Get(Value, 0))));
        }
Exemple #31
0
 public ReaderCommand(
     DrdaStreamReader reader,
     UInt32 totalByteLength,
     CodePoint codePoint)
 {
     _totalByteLength = totalByteLength - BaseSize;
     CodePoint        = codePoint;
     Reader           = reader;
 }
Exemple #32
0
 public BytesParameter(
     DrdaStreamReader reader,
     UInt32 byteArraySize,
     CodePoint codePoint)
     : this(
         codePoint,
         reader.ReadBytes(
             byteArraySize - BaseSize))
 {
 }
Exemple #33
0
 private static void AssertEqual <T>(T expected, T actual, string methodName, CodePoint codePoint)
 {
     if (!EqualityComparer <T> .Default.Equals(expected, actual))
     {
         throw new AssertActualExpectedException(
                   expected: expected,
                   actual: actual,
                   userMessage: FormattableString.Invariant($"CharUnicodeInfo.{methodName}({codePoint}) returned unexpected value."));
     }
 }
        public void CodePoint_ToString()
        {
            ICodeModel codeModel = new CodeModel();
            var        activity  = MessageFactory.Text("hi");
            var        context   = new TurnContext(new TestAdapter(), activity);
            var        dc        = new DialogContext(new DialogSet(), context, new DialogState());
            ICodePoint codePoint = new CodePoint(codeModel, dc, "test-item", "more");

            Assert.Equal(codePoint.ToString(), codePoint.Name);
        }
Exemple #35
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ActionState"/> class.
		/// </summary>
		/// <param name="stack"></param>
		/// <param name="state"></param>
		/// <param name="currentToken"></param>
		public ActionState(Frame stack, StateRef state, CodePoint currentToken)
			: this()
		{
			#region Contract
			Contract.Requires<ArgumentNullException>(stack != null);
			#endregion

			this.Stack = stack;
			this.NextState = state;
			this.CurrentToken = currentToken;
		}
 private static UnicodeBlockInfo Find(UnicodeBlockInfo[] blocks, CodePoint c)
 {
     int i = BinarySearch(blocks, c);
     if (i < 0)
     {
         i = ~i;
         --i;
     }
     var block = blocks[i];
     if (block.LastCodePoint < c)
     {
         return null;
     }
     return block;
 }
Exemple #37
0
        public static bool TryDecode(ReadOnlySpan buffer, ref int index, out CodePoint codePoint)
        {
            codePoint = default(CodePoint);

            if (index >= buffer.Length) return false;

            uint code = buffer[index];

            if (code < 0b1100_0000)
            {
                // ASCII 文字
                codePoint = new CodePoint(code);
                ++index;
                return true;
            }
            if (code < 0b1110_0000)
            {
                // 2バイト文字
                if (index + 1 >= buffer.Length) return false;
                code &= 0b1_1111;
                code = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
                ++index;
                codePoint = new CodePoint(code);
                return true;
            }
            if (code < 0b1111_0000)
            {
                // 3バイト文字
                if (index + 2 >= buffer.Length) return false;
                code &= 0b1111;
                code = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
                code = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
                ++index;
                codePoint = new CodePoint(code);
                return true;
            }

            // 4バイト文字
            if (index + 3 >= buffer.Length) return false;
            code &= 0b0111;
            code = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
            code = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
            code = (code << 6) | (uint)(buffer[++index] & 0b0011_1111);
            ++index;
            codePoint = new CodePoint(code);
            return true;
        }
Exemple #38
0
		public void AddOneElement()
		{
			// Arrange
			var sut = new CodePointSet();
			var v = new CodePoint(123);

			// Act
			sut.Add(v);

			// Assert
			Assert.That(sut.IsEmpty, Is.False);
			Assert.That(sut.Count, Is.EqualTo(1));
			Assert.That(sut, Is.EquivalentTo(new [] { v }));
			Assert.That(sut.Contains(v), Is.True);
			Assert.That(sut.Contains(v - 1), Is.False);
			Assert.That(sut.Contains(v + 1), Is.False);
			Assert.That(sut.GetRanges(), Is.EquivalentTo(new []{ new CodePointRange(v, v) }));
		}
Exemple #39
0
		public void AddAdjacentElementBeforeMerges()
		{
			// Arrange
			var sut = new CodePointSet();
			var v1 = new CodePoint(123);
			var v2 = v1 + 1;

			// Act
			sut.Add(v2);
			sut.Add(v1);

			// Assert
			Assert.That(sut.IsEmpty, Is.False);
			Assert.That(sut.Count, Is.EqualTo(2));
			Assert.That(sut, Is.EquivalentTo(new [] { v1, v2 }));
			Assert.That(sut.Contains(v1), Is.True);
			Assert.That(sut.Contains(v2), Is.True);
			Assert.That(sut.GetRanges(), Is.EquivalentTo(new[] { new CodePointRange(v1, v2) }));
		}
 private static int BinarySearch(UnicodeBlockInfo[] blocks, CodePoint c)
 {
     int lo, hi;
     lo = 0;
     hi = blocks.Length - 1;
     while (lo <= hi)
     {
         int mi = lo + (hi - lo) / 2;
         var blockFirstCp = blocks[mi].FirstCodePoint;
         if (blockFirstCp < c)
         {
             lo = mi + 1;
         }
         else if (c < blockFirstCp)
         {
             hi = mi - 1;
         }
         else
         {
             return mi;
         }
     }
     return ~lo;
 }
 public static bool IsIdentifierChar_NonFirst(CodePoint c)
 {
     if (c.IsNull)
     {
         throw new ArgumentOutOfRangeException();
     }
     int cv = c.Value;
     if (cv < 128)
     {
         if ('A' <= cv && cv <= 'Z')
         {
             return true;
         }
         if ('a' <= cv && cv <= 'z')
         {
             return true;
         }
         if ('0' <= cv && cv <= '9')
         {
             return true;
         }
         return cv == '_' || cv == '@' || cv == '#' || cv == '$';
     }
     var uc = Identifier_GetUnicodeCategory(c);
     return uc == UnicodeCategory.DecimalDigitNumber || uc.IsLetter();
 }
Exemple #42
0
        /// <summary>
        /// TODO : Documentation
        /// </summary>
        /// <returns></returns>
        private bool Populate()
        {
            bool result = true;
            _InnerCode = new List<CodePoint>();

            //
            // Add labels and source code
            //
            CodePoint p = new CodePoint();
            for ( int i = 0; i < _SourceCode.Count; i++ )
            {
                if ( _SourceCode[ i ].EndsWith( ":" ) && ( ! _SourceCode[i].Contains(" ") ) )
                {
                    p.Label = _SourceCode[ i ];
                }
                else
                {
                    p.Source = _SourceCode[ i ];
                    _InnerCode.Add( p );
                    p = new CodePoint();
                }
            }
            // Support for Label-at-the-end-of-code special case
            // Here: the CodePoint with label but without code is added
            if ( null != p.Label )
            {
                _InnerCode.Add( p );
            }

            for ( int i = 0; i < _InnerCode.Count; i++ )
            {
                string actionName;
                string statement = null;

                // Support for Label-at-the-end-of-code special case
                // Here: Don't try to render last label into code as it doesn't have any
                if ( null == _InnerCode[ i ].Source )
                    continue;

                try
                {
                    statement = PrepareAndReplaceLabel( _InnerCode[ i ].Source, out actionName );
                }
                catch ( AVM1ExceptionSourceFormat e )
                {
                    String s = String.Format( "Preparation failed: {0}, Error was: {1}", _InnerCode[ i ].Source, e.Message );
                    Log.Error(this, s);
                    result = false;
                    break;
                }

                try
                {
                    AbstractAction a;
                    if ( ( null != _OriginalInstructionMarker) && ( actionName.Equals( _OriginalInstructionMarker, StringComparison.InvariantCulture ) ) )
                    {
                        a = _OriginalInstruction;
                    }
                    else
                    {
                        a = AVM1.AVM1Factory.Create( actionName, statement );
                    }
                    _InnerCode[ i ].Code = a;
                   //Log.Debug(this,  a.ToString() );
                }
                catch ( AVM1ExceptionSourceFormat )
                {
                   Log.Error(this,  "Syntax error: " + _InnerCode[ i ].Source );
                    result = false;
                    break;
                }
            }

            if ( false == result )
                return result;

            // Support for Label-at-the-end-of-code special case
            // Here: remove the _InnerCode element, as it's no longer needed since the
            //       branch targets have been resolved to indices
            if ( null == _InnerCode[ _InnerCode.Count - 1 ].Source )
                _InnerCode.RemoveAt( _InnerCode.Count - 1 );

            //
            // resolve the branch targets (which are still indices) into actual
            // byte addresses
            //
            for ( int i = 0; i < _InnerCode.Count; i++ )
            {
                // TODO: make this better!
                if ( ( _InnerCode[ i ].Code.IsBranch )
                    || ( _InnerCode[ i ].Code.ActionType == AVM1Actions.ActionDefineFunction )
                    || ( _InnerCode[ i ].Code.ActionType == AVM1Actions.ActionDefineFunction2 ) )
                {
                    if ( _InnerCode[ i ].Code.BranchTarget > _InnerCode.Count )
                    {
                       Log.Error(this,  _InnerCode[ i ].Source + " branch target out of range (" +
                            _InnerCode[ i ].Code.BranchTarget.ToString( "d" ) + " > " +
                            _InnerCode.Count.ToString( "d" ) + ")" );
                        result = false;
                        break;
                    }

                    int replacementTarget = _InnerCode[ i ].Code.BranchTarget;
                    int begin = i < replacementTarget ? i : replacementTarget;
                    int end = i > replacementTarget ? i : replacementTarget;

                    uint codesize = 0;
                    for ( int j = begin; j < end; j++ )
                    {
                        codesize += _InnerCode[ j ].Code.ActionLength;
                    }
                    _InnerCode[ i ].Code.BranchTargetAdjusted = (int)(i < replacementTarget? codesize : ( -1 * codesize ));
                }
            }

            return result;
        }
Exemple #43
0
        /// <summary>
        /// Gets glyph data for a specific character.
        /// </summary>
        /// <param name="codePoint">The Unicode codepoint for which to retrieve glyph data.</param>
        /// <param name="pixelSize">The desired size of the font, in pixels.</param>
        /// <returns>The glyph data if the font supports the given character; otherwise, <c>null</c>.</returns>
        public Glyph GetGlyph(CodePoint codePoint, float pixelSize)
        {
            var glyphIndex = charMap.Lookup(codePoint);
            if (glyphIndex < 0)
                return null;

            // set up the control value table
            var scale = ComputeScale(pixelSize);
            interpreter.SetControlValueTable(controlValueTable, scale, pixelSize, prepProgram);

            // get metrics
            var glyph = glyphs[glyphIndex];
            var horizontal = hmetrics[glyphIndex];
            //var vtemp = vmetrics?[glyphIndex];
            //if (vtemp == null) {
            //    var synth = verticalSynthesized;
            //    synth.FrontSideBearing -= glyph.MaxY;
            //    vtemp = synth;
            //}
            MetricsEntry vtemp;
            if (vmetrics == null)
            {
                var synth = verticalSynthesized;
                synth.FrontSideBearing -= glyph.MaxY;
                vtemp = synth;
            }
            else
            {
                vtemp = vmetrics[glyphIndex];
            }
            //var vertical = vtemp.GetValueOrDefault();
            var vertical = vtemp;

            // build and transform the glyph
            var points = new List<PointF>(32);
            var contours = new List<int>(32);
            var transform = Matrix3x2.CreateScale(scale);
            Geometry.ComposeGlyphs(glyphIndex, 0, ref transform, points, contours, glyphs);

            // add phantom points; these are used to define the extents of the glyph,
            // and can be modified by hinting instructions
            var pp1 = new Point((FUnit)(glyph.MinX - horizontal.FrontSideBearing), (FUnit)0);
            var pp2 = new Point(pp1.X + (FUnit)horizontal.Advance, (FUnit)0);
            var pp3 = new Point((FUnit)0, (FUnit)(glyph.MaxY + vertical.FrontSideBearing));
            var pp4 = new Point((FUnit)0, pp3.Y - (FUnit)vertical.Advance);
            points.Add(pp1 * scale);
            points.Add(pp2 * scale);
            points.Add(pp3 * scale);
            points.Add(pp4 * scale);

            // hint the glyph's points
            var pointArray = points.ToArray();
            var contourArray = contours.ToArray();
            interpreter.HintGlyph(pointArray, contourArray, glyphs[glyphIndex].Instructions);

            return new Glyph(renderer, pointArray, contourArray, horizontal.Advance * scale);
        }
Exemple #44
0
        /// <summary>
        /// Gets kerning information for a pair of characters.
        /// </summary>
        /// <param name="left">The left character.</param>
        /// <param name="right">The right character.</param>
        /// <param name="pixelSize">The size of the font, in pixels.</param>
        /// <returns>The amount of kerning to apply, if any.</returns>
        public float GetKerning(CodePoint left, CodePoint right, float pixelSize)
        {
            if (kernTable == null)
                return 0.0f;

            var leftIndex = charMap.Lookup(left);
            var rightIndex = charMap.Lookup(right);
            if (leftIndex < 0 || rightIndex < 0)
                return 0.0f;

            var kern = kernTable.Lookup(leftIndex, rightIndex);
            return kern * ComputeScale(pixelSize);
        }
 public void TestInitialize()
 {
     this._element = new CodePoint();
     this._provider = this._element;
 }
 public void CodePoint_InvalidCode_RegularChar()
 {
     // Go through the constructor as well.
     CodePoint cp = new CodePoint((int)'a');
 }
Exemple #47
0
		public void RemoveElementInMiddleOfRange()
		{
			// Arrange
			var sut = new CodePointSet();
			var v1 = new CodePoint(123);
			var v2 = v1 + 1;
			var v3 = v2 + 1;
			sut.Add(v1);
			sut.Add(v2);
			sut.Add(v3);

			// Act
			sut.Remove(v2);

			// Assert
			Assert.That(sut.IsEmpty, Is.False);
			Assert.That(sut.Count, Is.EqualTo(2));
			Assert.That(sut, Is.EquivalentTo(new [] { v1, v3 }));
			Assert.That(sut.Contains(v1), Is.True);
			Assert.That(sut.Contains(v2), Is.False);
			Assert.That(sut.Contains(v3), Is.True);
			Assert.That(sut.GetRanges(), Is.EquivalentTo(new []{ new CodePointRange(v1, v1), new CodePointRange(v3, v3) }));
		}
Exemple #48
0
		// TODO: Can currentToken be removed?
		/// <summary>
		/// Enqueues the specified stack frame and next state for the shifter.
		/// </summary>
		/// <param name="stack">The current stack frame.</param>
		/// <param name="nextState">The next state.</param>
		/// <param name="currentToken">The current token.</param>
		public void EnqueueForShifter(Frame stack, StateRef nextState, CodePoint currentToken)
		{
			#region Contract
			Contract.Requires<ArgumentNullException>(stack != null);
			Contract.Requires<ArgumentNullException>(nextState != null);
			#endregion
			this.forShifter.PushFront(new ActionState(stack, nextState, currentToken));
		}
 public static CodePointDescription Find(CodePoint c, UnicodeVersion version = UnicodeVersion.V3_2)
 {
     if (c.IsNull)
     {
         throw new ArgumentNullException();
     }
     if (version == UnicodeVersion.V3_2)
     {
         CodePointDescription descr;
         DescrFromCodePointV3_2.Value.TryGetValue(c, out descr);
         return descr;
     }
     throw new ArgumentOutOfRangeException();
 }
		/// <inheritdoc />
		public IProductionParseNode CreateProduction(CodePoint token)
		{
			// CONTRACT: Inherited from IParseNodeFactory
			return new ProductionParseNode(token);
		}
Exemple #51
0
			public IProductionParseNode CreateProduction(CodePoint token)
			{
				Contract.Ensures(Contract.Result<IProductionParseNode>() != null);
				return default(IProductionParseNode);
			}
 public static bool IsIdentifierChar_First(CodePoint c)
 {
     if (c.IsNull)
     {
         throw new ArgumentOutOfRangeException();
     }
     int cv = c.Value;
     if (cv < 128)
     {
         if ('A' <= cv && cv <= 'Z')
         {
             return true;
         }
         if ('a' <= cv && cv <= 'z')
         {
             return true;
         }
         return cv == '_' || cv == '@' || cv == '#';
     }
     return Identifier_GetUnicodeCategory(c).IsLetter();
 }
 private static UnicodeCategory Identifier_GetUnicodeCategory(CodePoint c)
 {
     throw new NotImplementedException();
     var descr = CodePointDescription.Find(c, Identifier_UnicodeVersion);
     if (descr == null)
     {
         var blockInfo = UnicodeBlockInfo.Find(c, Identifier_UnicodeVersion);
         if (blockInfo.IsNotSupported)
         {
             throw new NotSupportedException();
         }
         return (UnicodeCategory)(-1);
     }
     return descr.Category;
 }
 public static UnicodeBlockInfo Find(CodePoint c, UnicodeVersion version = UnicodeVersion.V3_2)
 {
     if (c == CodePoint.Null)
     {
         throw new ArgumentOutOfRangeException();
     }
     if (version == UnicodeVersion.V3_2)
     {
         return Find(BlocksV3_2.Value, c);
     }
     throw new ArgumentOutOfRangeException();
 }
Exemple #55
0
		private ITerm GetProduction(CodePoint codepoint)
		{
			return termFactory.Int(unchecked((int)codepoint.Value));
		}