Beispiel #1
0
        public LineBreakpoints AnalyzeLineBreakpoints(IntPtr[] text_ptrs, uint[] lengths, CultureInfo culture,
                                                      Factory factory,
                                                      uint range_start, uint range_length, bool isRightToLeft, CultureInfo numberCulture,
                                                      bool ignoreUserOverride, uint numberSubstitutionMethod)
        {
            IDWriteTextAnalyzer pTextAnalyzer      = null;
            TextAnalyzerSink    textAnalyzerSink   = null;
            TextAnalyzerSource  textAnalyzerSource = null;

            IDWriteFactory pDWriteFactory = factory.DWriteFactory;

            pTextAnalyzer = pDWriteFactory.CreateTextAnalyzer();

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

            textAnalyzerSource = new TextAnalyzerSource(
                text_ptrs,
                lengths,
                culture.IetfLanguageTag,
                pDWriteFactory,
                isRightToLeft,
                numberSubstitutionLocaleName,
                ignoreUserOverride,
                numberSubstitutionMethod);

            textAnalyzerSink = new TextAnalyzerSink();

            textAnalyzerSink.InitializeLineBreakpoints((int)range_start, (int)(range_start + range_length));

            pTextAnalyzer.AnalyzeLineBreakpoints(textAnalyzerSource, range_start, range_length, textAnalyzerSink);

            return(textAnalyzerSink.LineBreakpoints);
        }
Beispiel #2
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);
            }
        }