コード例 #1
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
            YAMLMappingNode node = base.ExportYAMLRoot(container);

            node.AddSerializedVersion(GetSerializedVersion(container.ExportVersion));
            node.Add(LineSpacingName, LineSpacing);
            node.Add(DefaultMaterialName, DefaultMaterial.ExportYAML(container));
            node.Add(FontSizeName, FontSize);
            node.Add(TextureName, Texture.ExportYAML(container));
            node.Add(AsciiStartOffsetName, AsciiStartOffset);
            node.Add(TrackingName, GetTracking(container.Version));
            node.Add(CharacterSpacingName, CharacterSpacing);
            node.Add(CharacterPaddingName, GetCharacterPadding(container.Version));
            node.Add(ConvertCaseName, ConvertCase);
            node.Add(CharacterRectsName, CharacterRects.ExportYAML(container));
            node.Add(KerningValuesName, KerningValues.ExportYAML(container));
            node.Add(PixelScaleName, GetPixelScale(container.Version));
            node.Add(FontDataName, GetFontData(container.Version).ExportYAML());
            node.Add(AscentName, Ascent);
            node.Add(DescentName, Descent);
            node.Add(DefaultStyleName, (int)DefaultStyle);
            node.Add(FontNamesName, GetFontNames(container.Version).ExportYAML());
            node.Add(FallbackFontsName, GetFallbackFonts(container.Version).ExportYAML(container));
            node.Add(FontRenderingModeName, (int)FontRenderingMode);
            node.Add(UseLegacyBoundsCalculationName, UseLegacyBoundsCalculation);
            node.Add(ShouldRoundAdvanceValueName, GetShouldRoundAdvanceValue(container.Version));
            return(node);
        }
コード例 #2
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            bool isGrouped = IsFontGrouped(reader.Version);

            if (isGrouped)
            {
                LineSpacing = reader.ReadSingle();
                DefaultMaterial.Read(reader);
                FontSize = reader.ReadSingle();
                Texture.Read(reader);
                reader.AlignStream();
            }

            if (IsShortAsciiStartOffset(reader.Version))
            {
                AsciiStartOffset = reader.ReadInt16();
                FontCountX       = reader.ReadInt16();
                FontCountY       = reader.ReadInt16();
            }
            else
            {
                AsciiStartOffset = reader.ReadInt32();
                if (HasFontCount(reader.Version))
                {
                    FontCountX = reader.ReadInt32();
                    FontCountY = reader.ReadInt32();
                }
            }

            if (HasKerning(reader.Version))
            {
                Kerning = reader.ReadSingle();
            }
            if (HasTracking(reader.Version))
            {
                Tracking = reader.ReadSingle();
            }

            if (!isGrouped)
            {
                LineSpacing = reader.ReadSingle();
            }

            if (HasCharacterSpacing(reader.Version))
            {
                CharacterSpacing = reader.ReadInt32();
                CharacterPadding = reader.ReadInt32();
            }

            if (HasPerCharacterKerning(reader.Version))
            {
                if (IsBytePerCharacterKerning(reader.Version))
                {
                    PerCharacterKerningByte = reader.ReadTupleByteSingleArray();
                }
                else
                {
                    PerCharacterKerning = reader.ReadTupleIntSingleArray();
                }
            }

            ConvertCase = reader.ReadInt32();
            if (!isGrouped)
            {
                DefaultMaterial.Read(reader);
            }
            CharacterRects = reader.ReadAssetArray <CharacterInfo>();
            if (!isGrouped)
            {
                Texture.Read(reader);
            }

            if (HasGridFont(reader.Version))
            {
                if (IsGridFontFirst(reader.Version))
                {
                    GridFont = reader.ReadBoolean();
                }
            }

#warning TODO: create a dictionary with non unique keys
            if (IsByteKerningValues(reader.Version))
            {
                Dictionary <Tuple <byte, byte>, float> kerningValues = new Dictionary <Tuple <byte, byte>, float>();
                kerningValues.ReadSafe(reader);
                foreach (var kvp in kerningValues)
                {
                    Tuple <ushort, ushort> key = new Tuple <ushort, ushort>(kvp.Key.Item1, kvp.Key.Item2);
                    KerningValues.Add(key, kvp.Value);
                }
            }
            else
            {
                KerningValues.ReadSafe(reader);
            }

            if (HasPixelScale(reader.Version))
            {
                PixelScale = reader.ReadSingle();
                reader.AlignStream();
            }

            if (HasGridFont(reader.Version))
            {
                if (!IsGridFontFirst(reader.Version))
                {
                    GridFont = reader.ReadBoolean();
                    if (IsAlign(reader.Version))
                    {
                        reader.AlignStream();
                    }
                }
            }

            if (HasFontData(reader.Version))
            {
                FontData = reader.ReadByteArray();
                reader.AlignStream();

                if (!isGrouped)
                {
                    FontSize = reader.ReadSingle();
                }
                Ascent = reader.ReadSingle();
            }
            if (HasDescent(reader.Version))
            {
                Descent = reader.ReadSingle();
            }
            if (HasDefaultStyle(reader.Version))
            {
                DefaultStyle = (FontStyle)reader.ReadUInt32();
                FontNames    = reader.ReadStringArray();
            }

            if (HasFallbackFonts(reader.Version))
            {
                FallbackFonts = reader.ReadAssetArray <PPtr <Font> >();
                reader.AlignStream();

                FontRenderingMode = (FontRenderingMode)reader.ReadInt32();
            }

            if (HasUseLegacyBoundsCalculation(reader.Version))
            {
                UseLegacyBoundsCalculation = reader.ReadBoolean();
            }
            if (HasShouldRoundAdvanceValue(reader.Version))
            {
                ShouldRoundAdvanceValue = reader.ReadBoolean();
            }
        }