Ejemplo n.º 1
0
 public virtual void Write(Res_value data)
 {
     _writer.Write(data.Size);
     _writer.Write(data.Res0);
     _writer.Write((byte)data.DataType);
     _writer.Write(data.RawData);
 }
Ejemplo n.º 2
0
            /// <summary>Convert resource value to String</summary>
            /// <returns>String representation of the value</returns>
            public String DataToString()
            {
                switch (this.dataType)
                {
                case DATA_TYPE.NULL:
                    return(null);

                case DATA_TYPE.REFERENCE:
                    return("@" + data);

                case DATA_TYPE.ATTRIBUTE:
                    return("?" + data);

                case DATA_TYPE.FLOAT:
                    Byte[] bytes = BitConverter.GetBytes(data);
                    return(BitConverter.ToSingle(bytes, 0).ToString());

                case DATA_TYPE.INT_BOOLEAN:
                    return(this.data != 0 ? "true" : "false");

                case DATA_TYPE.INT_HEX:
                    return("0x" + this.data.ToString("X4"));

                case DATA_TYPE.DIMENSION:
                    Single dim = complexToFloat(data);
                    return(dim.ToString() + DIMENSION_UNIT_STRS[(this.data >> COMPLEX_UNIT_SHIFT) & COMPLEX_UNIT_MASK]);

                case DATA_TYPE.FRACTION:
                    Single fraction = complexToFloat(data) * 100;
                    return(fraction.ToString() + FRACTION_UNIT_STRS[(this.data >> COMPLEX_UNIT_SHIFT) & COMPLEX_UNIT_MASK]);

                case DATA_TYPE.INT_COLOR_RGB8:
                    return("#" + Res_value.ToColorRGB8(this.data));

                case DATA_TYPE.INT_COLOR_RGB4:
                    return("#" + Res_value.ToColorRGB4(this.data));

                case DATA_TYPE.INT_COLOR_ARGB8:
                    return("#" + Res_value.ToColorARGB8(this.data));

                default:
                    return(this.data.ToString());
                }
            }
Ejemplo n.º 3
0
        private string FormatValue(Res_value value)
        {
            Color c;
            int   index0;

            switch (value.DataType)
            {
            case Res.ValueType.TYPE_STRING:
                return(_parser.Strings.GetString(value.StringValue));

            case Res.ValueType.TYPE_NULL:
                return("null");

            case Res.ValueType.TYPE_FLOAT:
                return(value.FloatValue.ToString("g"));

            case Res.ValueType.TYPE_FRACTION:
                index0 = (int)value.ComplexFractionUnit;
                return(string.Format(
                           "{0:g}{1}", value.ComplexValue,
                           index0 < 2 ? new[] { "%", "%p" }[index0] : "?"));

            case Res.ValueType.TYPE_DIMENSION:
                index0 = (int)value.ComplexDimensionUnit;
                return(string.Format(
                           "{0:g}{1}", value.ComplexValue,
                           index0 < 6 ? new[] { "px", "dip", "sp", "pt", "in", "mm" }[index0] : "?"));

            case Res.ValueType.TYPE_INT_DEC:
                return(string.Format("{0:d}", value.IntValue));

            case Res.ValueType.TYPE_INT_HEX:
                return(string.Format("0x{0:x}", value.IntValue));

            case Res.ValueType.TYPE_INT_BOOLEAN:
                return(value.IntValue == 0 ? "false" : "true");

            case Res.ValueType.TYPE_INT_COLOR_ARGB8:
                c = value.ColorValue;
                return(string.Format("#{0:x2}{1:x2}{2:x2}{3:x2}", c.A, c.R, c.G, c.B));

            case Res.ValueType.TYPE_INT_COLOR_ARGB4:
                c = value.ColorValue;
                return(string.Format("#{0:x1}{1:x1}{2:x1}{3:x1}", c.A / 51, c.R / 51, c.G / 51, c.B / 51));

            case Res.ValueType.TYPE_INT_COLOR_RGB8:
                c = value.ColorValue;
                return(string.Format("#{0:x2}{1:x2}{2:x2}", c.R, c.G, c.B));

            case Res.ValueType.TYPE_INT_COLOR_RGB4:
                c = value.ColorValue;
                return(string.Format("#{0:x1}{1:x1}{2:x1}", c.R / 51, c.G / 51, c.B / 51));

            case Res.ValueType.TYPE_REFERENCE:
                uint?ident = value.ReferenceValue.Ident;
                if (ident == null)
                {
                    return("@undef");
                }
                return(string.Format("@{0:x8}", ident.Value));

            default:
                return(string.Format("({0}:{1:x8})", value.DataType, value.RawData));
            }
        }
Ejemplo n.º 4
0
        private static string FormatValue(ResXmlParser parser, Res_value value)
        {
            Color c;
            int   index0;

            switch (value.DataType)
            {
            case ValueType.TYPE_STRING:
                return(parser.GetString(value.StringValue));

            case ValueType.TYPE_NULL:
                return("null");

            case ValueType.TYPE_FLOAT:
                return(value.FloatValue.ToString("g"));

            case ValueType.TYPE_FRACTION:
                index0 = (int)value.ComplexFractionUnit;
                return($"{value.ComplexValue:g}{(index0 < 2 ? new[] {"%", "%p"}[index0] : "?")}");

            case ValueType.TYPE_DIMENSION:
                index0 = (int)value.ComplexDimensionUnit;
                return
                    ($"{value.ComplexValue:g}{(index0 < 6 ? new[] {"px", "dip", "sp", "pt", "in", "mm"}[index0] : "?")}");

            case ValueType.TYPE_INT_DEC:
                return($"{value.IntValue:d}");

            case ValueType.TYPE_INT_HEX:
                return($"0x{value.IntValue:x}");

            case ValueType.TYPE_INT_BOOLEAN:
                return(value.IntValue == 0 ? "false" : "true");

            case ValueType.TYPE_INT_COLOR_ARGB8:
                c = value.ColorValue;
                return($"#{c.A:x2}{c.R:x2}{c.G:x2}{c.B:x2}");

            case ValueType.TYPE_INT_COLOR_ARGB4:
                c = value.ColorValue;
                return($"#{c.A / 51:x1}{c.R / 51:x1}{c.G / 51:x1}{c.B / 51:x1}");

            case ValueType.TYPE_INT_COLOR_RGB8:
                c = value.ColorValue;
                return($"#{c.R:x2}{c.G:x2}{c.B:x2}");

            case ValueType.TYPE_INT_COLOR_RGB4:
                c = value.ColorValue;
                return($"#{c.R / 51:x1}{c.G / 51:x1}{c.B / 51:x1}");

            case ValueType.TYPE_REFERENCE:
                var ident = value.ReferenceValue.Ident;
                if (ident == null)
                {
                    return("@undef");
                }
                return($"@{ident.Value:x8}");

            default:
                return($"({value.DataType}:{value.RawData:x8})");
            }
        }