Example #1
0
        public void addFont(Font font, string familyName,
                            FontWeight fontWeight = null, FontStyle fontStyle = FontStyle.normal)
        {
            if (fontWeight == null)
            {
                fontWeight = FontWeight.normal;
            }

            FontRef fontRef = new FontRef(familyName, fontWeight, fontStyle);

            D.assert(font != null);
            D.assert(font.dynamic, $"adding font which is not dynamic is not allowed {font.name}");
            font.hideFlags = HideFlags.DontSave & ~HideFlags.DontSaveInBuild;

            FontInfo current;

            this._fonts.TryGetValue(fontRef, out current);
            D.assert(current == null || current.font == font, $"font with key {fontRef} already exists");
            var fontInfo = new FontInfo(font);

            this._fonts[fontRef] = fontInfo;
        }
Example #2
0
        internal FontInfo getOrCreate(string familyName, FontWeight fontWeight, FontStyle fontStyle)
        {
            if (fontWeight == null)
            {
                fontWeight = FontWeight.normal;
            }
            FontRef fontRef = new FontRef(familyName, fontWeight, fontStyle);

            if (this._fonts.TryGetValue(fontRef, out var fontInfo))
            {
                return(fontInfo);
            }

            // fallback to normal weight & style
            if (fontWeight != FontWeight.normal || fontStyle != FontStyle.normal)
            {
                fontInfo = this.getOrCreate(familyName, FontWeight.normal, FontStyle.normal);
                if (fontInfo != null)
                {
                    return(fontInfo);
                }
            }

            var osFont = Font.CreateDynamicFontFromOSFont(familyName, defaultFontSize);

            osFont.hideFlags                      = HideFlags.DontSave;
            osFont.material.hideFlags             = HideFlags.DontSave;
            osFont.material.mainTexture.hideFlags = HideFlags.DontSave;

            var newFont = new FontInfo(osFont);

            fontRef = new FontRef(familyName, fontWeight, fontStyle);
            this._fonts[fontRef] = newFont;

            return(newFont);
        }