示例#1
0
        public static FontMetricsData CreateFontMetricsData(byte[] binData)
        {
            FontMetricsData data     = new FontMetricsData();
            int             tableNum = GetUin16(binData, 4);

            for (int i = 0; i < tableNum; ++i)
            {
                string header = GetString(binData, 12 + i * 16, 4);
                uint   offset = GetUin32(binData, 12 + i * 16 + 8);
                uint   size   = GetUin32(binData, 12 + i * 16 + 12);

                if (header == "head")
                {
                    // emHeight offset + 18
                    System.Console.WriteLine(header + ";;" + offset);
                    data.emHeight = GetUin16(binData, (int)offset + 18);
                }
                else if (header == "hhea")
                {
                    System.Console.WriteLine(header + ";;" + offset);
                    data.ascent  = GetSint16(binData, (int)offset + 4);
                    data.descent = -GetSint16(binData, (int)offset + 6);
                    data.leading = GetSint16(binData, (int)offset + 8);
                }
            }
            return(data);
        }
示例#2
0
        private FontMetricsData GetMetricData(Font font)
        {
            FontMetricsData data;

            if (this.metricDictionary.TryGetValue(font, out data))
            {
                return(data);
            }
            data = FontMetricsData.CreateFontMetricsData(AssetDatabase.GetAssetPath(font));
            this.metricDictionary.Add(font, data);
            return(data);
        }
示例#3
0
        /// <summary>
        /// Execute adjust
        /// </summary>
        /// <param name="text">UI TextComponent</param>
        /// <returns>true if changed</returns>
        public bool Execute(Text text)
        {
            Font font = text.font;

            if (font == null)
            {
                return(false);
            }
            FontMetricsData metrics = this.GetMetricData(font);

            if (metrics == null)
            {
                return(false);
            }

            float param = metrics.GetCalculatedLeading(text.fontSize) * GetAlignmentParameter(text.alignment);

            param *= text.rectTransform.localScale.y;

            float oldPositionY = text.rectTransform.position.y;

            if (positionUp)
            {
                text.rectTransform.localPosition = text.rectTransform.localPosition +
                                                   Vector3.up * param;
            }
            else
            {
                text.rectTransform.localPosition = text.rectTransform.localPosition +
                                                   Vector3.down * param;
            }
            // update children of textComponent
            foreach (RectTransform child in text.rectTransform)
            {
                child.localPosition = child.localPosition + Vector3.up * (oldPositionY - text.rectTransform.position.y) / text.rectTransform.lossyScale.y;
            }
            return(true);
        }
示例#4
0
        void OnGUI()
        {
            var oldFont = currentFont;

            scrollPos   = EditorGUILayout.BeginScrollView(scrollPos);
            currentFont = (Font)EditorGUILayout.ObjectField(currentFont, typeof(UnityEngine.Font), false);
            if (currentFont == null)
            {
                EditorGUILayout.EndScrollView();
                return;
            }
            EditorGUILayout.LabelField("Information");
            OutputData("ascent", "" + currentFont.ascent);
            OutputData("dynamic", "" + currentFont.dynamic);
            OutputData("fontSize", "" + currentFont.fontSize);
            OutputData("lineHeight", "" + currentFont.lineHeight);
            OutputData("path", AssetDatabase.GetAssetPath(currentFont));

            EditorGUILayout.LabelField("");
            EditorGUILayout.LabelField("Parsed Data");
            if (oldFont != currentFont)
            {
                parsedFontMetricsData = FontMetricsData.CreateFontMetricsData(AssetDatabase.GetAssetPath(currentFont));
            }
            if (parsedFontMetricsData == null)
            {
                EditorGUILayout.EndScrollView();
                return;
            }
            OutputData("ascent", "" + parsedFontMetricsData.ascent);
            OutputData("descent", "" + parsedFontMetricsData.descent);
            OutputData("emHeight", "" + parsedFontMetricsData.emHeight);
            OutputData("leading", "" + parsedFontMetricsData.leading);
            OutputData("lineSpace", "" + parsedFontMetricsData.lineSpace);

            EditorGUILayout.LabelField("");
            EditorGUILayout.LabelField("Calculate Data");
            OutputData("ascent", "" + parsedFontMetricsData.GetCalculatedAscent(currentFont.fontSize));
            OutputData("descent", "" + parsedFontMetricsData.GetCalculatedDescent(currentFont.fontSize));
            OutputData("leading", "" + parsedFontMetricsData.GetCalculatedLeading(currentFont.fontSize));
            OutputData("lineSpace", "" + parsedFontMetricsData.GetCalculatedLineSpace(currentFont.fontSize));

            EditorGUILayout.LabelField("");
            EditorGUILayout.LabelField("CharacterInfo");
            var str = EditorGUILayout.TextField(charaInfoCh.ToString());

            if (str.Length > 0)
            {
                charaInfoCh = str[0];
            }
            CharacterInfo aInfo;

            if (!currentFont.GetCharacterInfo(charaInfoCh, out aInfo, currentFont.fontSize))
            {
                currentFont.RequestCharactersInTexture(charaInfoCh.ToString(), currentFont.fontSize);
                if (!currentFont.GetCharacterInfo(charaInfoCh, out aInfo, currentFont.fontSize))
                {
                    EditorGUILayout.EndScrollView();
                    return;
                }
            }
            OutputData("advance", "" + aInfo.advance);
            OutputData("bearing", "" + aInfo.bearing);
            OutputData("glyphHeight", "" + aInfo.glyphHeight);
            OutputData("maxY", "" + aInfo.maxY);
            OutputData("minY", "" + aInfo.minY);
            OutputData("size", "" + aInfo.size);

            EditorGUILayout.EndScrollView();
            //        currentFont.characterInfo[0].
            //        currentFont.GetCharacterInfo
        }