<commit_before>﻿//MIT, 2014-2017, WinterDev    
using System.Collections.Generic;
using Typography.OpenFont;
using Typography.TextLayout;


namespace Typography.TextServices
{

    public struct BreakSpan
    {
        public int startAt;
        public ushort len;
        public short flags;
        public ScriptLang scLang;

    }

    public class TextServices
    {
        //user can do text shaping by their own
        //this class is optional
        //it provide cache for previous 'used/ wellknown' Word-glyphPlans for a specific font 
        // 

        GlyphPlanCacheForTypefaceAndScriptLang _currentShapingContext;
        Dictionary<TextShapingContextKey, GlyphPlanCacheForTypefaceAndScriptLang> _registerShapingContexts = new Dictionary<TextShapingContextKey, GlyphPlanCacheForTypefaceAndScriptLang>();
        GlyphLayout _glyphLayout;

        Typeface _currentTypeface;
        float _fontSizeInPts;
        ScriptLang _defaultScriptLang;
        TypefaceStore typefaceStore;


        //GlyphPlanList userGlyphPlanList;
        //List<UserCharToGlyphIndexMap> userCharToGlyphMapList;

        public TextServices()
        {

            typefaceStore = new TypefaceStore();
            typefaceStore.FontCollection = InstalledFontCollection.GetSharedFontCollection(null);

            _glyphLayout = new GlyphLayout();
        }
        public bool TrySettingScriptLangFromCurrentThreadCultureInfo()
        {
            //accessory...
            var currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
            Typography.OpenFont.ScriptLang scLang = null;
            string langFullName;
            if (IcuData.TryGetFullLanguageNameFromLangCode(
                 currentCulture.TwoLetterISOLanguageName,
                 currentCulture.ThreeLetterISOLanguageName,
                 out langFullName))
            {
                SetDefaultScriptLang(scLang);
                SetCurrentScriptLang(Typography.OpenFont.ScriptLangs.GetRegisteredScriptLangFromLanguageName(langFullName));
                return true;
            }
            return false;
        }
        public void SetDefaultScriptLang(ScriptLang scLang)
        {
            _defaultScriptLang = scLang;
        }
        public void SetCurrentScriptLang(ScriptLang scLang)
        {
            _glyphLayout.ScriptLang = scLang;

        }

        public void SetCurrentFont(Typeface typeface, float fontSizeInPts)
        {<commit_msg>9814: set default script lang<commit_after>﻿//MIT, 2014-2017, WinterDev    
using System.Collections.Generic;
using Typography.OpenFont;
using Typography.TextLayout;


namespace Typography.TextServices
{

    public struct BreakSpan
    {
        public int startAt;
        public ushort len;
        public short flags;
        public ScriptLang scLang;

    }

    public class TextServices
    {
        //user can do text shaping by their own
        //this class is optional
        //it provide cache for previous 'used/ wellknown' Word-glyphPlans for a specific font 
        // 

        GlyphPlanCacheForTypefaceAndScriptLang _currentShapingContext;
        Dictionary<TextShapingContextKey, GlyphPlanCacheForTypefaceAndScriptLang> _registerShapingContexts = new Dictionary<TextShapingContextKey, GlyphPlanCacheForTypefaceAndScriptLang>();
        GlyphLayout _glyphLayout;

        Typeface _currentTypeface;
        float _fontSizeInPts;
        ScriptLang _defaultScriptLang;
        TypefaceStore typefaceStore;


        //GlyphPlanList userGlyphPlanList;
        //List<UserCharToGlyphIndexMap> userCharToGlyphMapList;

        public TextServices()
        {

            typefaceStore = new TypefaceStore();
            typefaceStore.FontCollection = InstalledFontCollection.GetSharedFontCollection(null);

            _glyphLayout = new GlyphLayout();
        }
        public bool TrySettingScriptLangFromCurrentThreadCultureInfo()
        {
            //accessory...
            var currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
            Typography.OpenFont.ScriptLang scLang = null;
            string langFullName;
            if (IcuData.TryGetFullLanguageNameFromLangCode(
                 currentCulture.TwoLetterISOLanguageName,
                 currentCulture.ThreeLetterISOLanguageName,
                 out langFullName))
            {
                scLang = Typography.OpenFont.ScriptLangs.GetRegisteredScriptLangFromLanguageName(langFullName);
                SetDefaultScriptLang(scLang);
                SetCurrentScriptLang(scLang);
                return true;
            }

            throw new System.NotSupportedException();
            return false;
        }
        public void SetDefaultScriptLang(ScriptLang scLang)
        {
            _defaultScriptLang = scLang;
        }
        public void SetCurrentScriptLang(ScriptLang scLang)
        {
            _glyphLayout.ScriptLang = scLang;

        }

        public void SetCurrentFont(Typeface typeface, float fontSizeInPts)
        {
{'fraction_non_alphanumeric': 0.057080350039777246, 'fraction_numerical': 0.003977724741447892, 'mean_word_length': 2.328259430840503, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5713624', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1232, 'n_words': 263}