Пример #1
0
        static IList <Span> AnalyzeExtendedAndItemize(
            TextItemizer textItemizer,
            IntPtr text,
            uint length,
            CultureInfo numberCulture,
            IClassification classification
            )
        {
            Debug.Assert(length >= 0);

            CharAttribute[] pCharAttribute = new CharAttribute[length];

            // Analyze the extended character ranges.
            AnalyzeExtendedCharactersAndDigits(text, length, textItemizer, pCharAttribute, numberCulture, classification);
            return(textItemizer.Itemize(numberCulture, pCharAttribute));
        }
Пример #2
0
        public static void AnalyzeExtendedCharactersAndDigits(
            IntPtr text,
            uint length,
            TextItemizer textItemizer,
            CharAttribute[]                                  pCharAttribute,
            CultureInfo numberCulture,
            IClassification classificationUtility
            )
        {
            // Text will never be of zero length. This is enforced by Itemize().
            bool isCombining;
            bool needsCaretInfo;
            bool isIndic;
            bool isDigit;
            bool isLatin;
            bool isStrong;
            bool isExtended;

            char ch = (char)Marshal.ReadInt16(text);

            classificationUtility.GetCharAttribute(
                ch,
                out isCombining,
                out needsCaretInfo,
                out isIndic,
                out isDigit,
                out isLatin,
                out isStrong
                );

            isExtended = ItemizerHelper.IsExtendedCharacter(ch);

            uint isDigitRangeStart    = 0;
            uint isDigitRangeEnd      = 0;
            bool previousIsDigitValue = (numberCulture == null) ? false : isDigit;
            bool currentIsDigitValue;

            // pCharAttribute is assumed to have the same length as text. This is enforced by Itemize().
            pCharAttribute[0] = (CharAttribute)
                                (((isCombining)    ? CharAttribute.IsCombining    : CharAttribute.None)
                                 | ((needsCaretInfo) ? CharAttribute.NeedsCaretInfo : CharAttribute.None)
                                 | ((isLatin)        ? CharAttribute.IsLatin        : CharAttribute.None)
                                 | ((isIndic)        ? CharAttribute.IsIndic        : CharAttribute.None)
                                 | ((isStrong)       ? CharAttribute.IsStrong       : CharAttribute.None)
                                 | ((isExtended)     ? CharAttribute.IsExtended     : CharAttribute.None));

            uint i;

            for (i = 1; i < length; ++i)
            {
                ch = (char)Marshal.ReadInt16(text, 2 * (int)i);

                classificationUtility.GetCharAttribute(
                    ch,
                    out isCombining,
                    out needsCaretInfo,
                    out isIndic,
                    out isDigit,
                    out isLatin,
                    out isStrong
                    );

                isExtended = ItemizerHelper.IsExtendedCharacter(ch);


                pCharAttribute[i] = (CharAttribute)
                                    (((isCombining)    ? CharAttribute.IsCombining    : CharAttribute.None)
                                     | ((needsCaretInfo) ? CharAttribute.NeedsCaretInfo : CharAttribute.None)
                                     | ((isLatin)        ? CharAttribute.IsLatin        : CharAttribute.None)
                                     | ((isIndic)        ? CharAttribute.IsIndic        : CharAttribute.None)
                                     | ((isStrong)       ? CharAttribute.IsStrong       : CharAttribute.None)
                                     | ((isExtended)     ? CharAttribute.IsExtended     : CharAttribute.None));


                currentIsDigitValue = (numberCulture == null) ? false : isDigit;
                if (previousIsDigitValue != currentIsDigitValue)
                {
                    isDigitRangeEnd = i;
                    textItemizer.SetIsDigit(isDigitRangeStart, isDigitRangeEnd - isDigitRangeStart, previousIsDigitValue);

                    isDigitRangeStart    = i;
                    previousIsDigitValue = currentIsDigitValue;
                }
            }


            isDigitRangeEnd = i;
            textItemizer.SetIsDigit(isDigitRangeStart, isDigitRangeEnd - isDigitRangeStart, previousIsDigitValue);
        }
Пример #3
0
        unsafe static public IList <Span> Itemize(
            char *text,
            uint length,
            CultureInfo culture,
            Factory factory,
            bool isRightToLeftParagraph,
            CultureInfo numberCulture,
            bool ignoreUserOverride,
            uint numberSubstitutionMethod,
            IClassification classificationUtility
            )
        {
            // If a text has zero length then we do not need to itemize.
            if (length > 0)
            {
                IDWriteTextAnalyzer pTextAnalyzer      = null;
                TextAnalyzerSink    textAnalyzerSink   = null;
                TextAnalyzerSource  textAnalyzerSource = null;

                IDWriteFactory pDWriteFactory = factory.DWriteFactory;

                pTextAnalyzer = pDWriteFactory.CreateTextAnalyzer();

                string numberSubstitutionLocaleName = numberCulture != null ? numberCulture.IetfLanguageTag : null;

                // NOTE: the text parameter is NOT copied inside TextAnalysisSource to improve perf.
                // This is ok as long as we use the TextAnalysisSource in the same scope as we hold ref to text.
                // If we are ever to change this pattern then this should be revisited in TextAnalysisSource in
                // PresentationNative.
                textAnalyzerSource = new TextAnalyzerSource(
                    text,
                    length,
                    culture.IetfLanguageTag,
                    pDWriteFactory,
                    isRightToLeftParagraph,
                    numberSubstitutionLocaleName,
                    ignoreUserOverride,
                    numberSubstitutionMethod);

                textAnalyzerSink = new TextAnalyzerSink();

                // Analyze the script ranges.
                pTextAnalyzer.AnalyzeScript(textAnalyzerSource,
                                            0,
                                            length,
                                            textAnalyzerSink);

                // Analyze the number substitution ranges.
                pTextAnalyzer.AnalyzeNumberSubstitution(textAnalyzerSource,
                                                        0,
                                                        length,
                                                        textAnalyzerSink);

                var dwriteScriptAnalysisList     = textAnalyzerSink.ScriptAnalysis;
                var dwriteNumberSubstitutionList = textAnalyzerSink.NumberSubstitution;

                TextItemizer textItemizer = new TextItemizer(dwriteScriptAnalysisList, dwriteNumberSubstitutionList);

                return(AnalyzeExtendedAndItemize(textItemizer, new IntPtr(text), length, numberCulture, classificationUtility));
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
 internal unsafe static void AnalyzeExtendedCharactersAndDigits(ushort *text, uint length, TextItemizer textItemizer, byte *pCharAttribute, CultureInfo numberCulture, IClassification classificationUtility)
 {
 }