private static double ReadPathDouble(BamlBinaryReader reader, bool isInt) { if (isInt) return reader.ReadInt32() * 1E-06; return reader.ReadCompressedDouble(); }
private static void AddPathPoint(BamlBinaryReader reader, StringBuilder sb) { sb.AppendFormat("{0},{1} ", reader.ReadCompressedDouble(), reader.ReadCompressedDouble()); }
private void ReadPropertyCustom(BamlBinaryReader reader) { short attributeIdentifier = reader.ReadInt16(); short serializerTypeIdentifierOriginal = reader.ReadInt16(); bool typeIdentifier = (serializerTypeIdentifierOriginal & 0x4000) == 0x4000; short serializerTypeIdentifier = (short)(serializerTypeIdentifierOriginal & ~0x4000); Property property = new Property(PropertyType.Value); property.PropertyDeclaration = this.GetPropertyDeclaration(attributeIdentifier); switch (serializerTypeIdentifier) { // PropertyReference case 0x0089: short identifier = reader.ReadInt16(); if (typeIdentifier) { TypeDeclaration declaringType = this.GetTypeDeclaration(identifier); string propertyName = reader.ReadString(); property.Value = new PropertyDeclaration(propertyName, declaringType); } else { property.Value = this.GetPropertyDeclaration(identifier); } break; case 0x002e: // Boolean int value = reader.ReadByte(); property.Value = (value == 0x01) ? "true" : "false"; break; case 0x02e8: // SolidColorBrush switch (reader.ReadByte()) { case 0x01: // KnownSolidColor uint color = reader.ReadUInt32(); switch (color) { case 0x00ffffff: property.Value = "Transparent"; break; default: property.Value = KnownColors.KnownColorFromUInt(color); break; } break; case 0x02: // OtherColor property.Value = reader.ReadString(); break; default: throw new NotSupportedException(); } break; case 0x02e9: // IntCollection using (StringWriter writer = new StringWriter()) { byte format = reader.ReadByte(); int count = reader.ReadInt32(); switch (format) { case 0x01: // Consecutive for (int i = 0; i < count; i++) { if (i != 0) { writer.Write(","); } int number = reader.ReadInt32(); writer.Write(number.ToString()); if (number > count) { break; } } break; case 0x02: // Byte for (int i = 0; i < count; i++) { if (i != 0) { writer.Write(","); } int number = reader.ReadByte(); writer.Write(number.ToString()); } break; case 0x03: // UInt16 for (int i = 0; i < count; i++) { if (i != 0) { writer.Write(","); } int number = reader.ReadUInt16(); writer.Write(number.ToString()); } break; case 0x04: // UInt32 throw new NotSupportedException(); default: throw new NotSupportedException(); } property.Value = writer.ToString(); } break; case 0x02ea: // PathData property.Value = PathDataParser.ParseStreamGeometry(reader); break; case 0x02ec: // Point using (StringWriter writer = new StringWriter()) { int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { if (i != 0) { writer.Write(" "); } for (int j = 0; j < 2; j++) { if (j != 0) { writer.Write(","); } double number = reader.ReadCompressedDouble(); writer.Write(number.ToString()); } } property.Value = writer.ToString(); } break; case 0x02eb: // Point3D case 0x02f0: // Vector3D using (StringWriter writer = new StringWriter()) { int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { if (i != 0) { writer.Write(" "); } for (int j = 0; j < 3; j++) { if (j != 0) { writer.Write(","); } double number = reader.ReadCompressedDouble(); writer.Write(number.ToString()); } } property.Value = writer.ToString(); } break; default: property.Value = String.Format("Not supported serializer type identifier: 0x{0:x}", serializerTypeIdentifier); break; //throw new NotSupportedException(); } Element element = (Element)this.elementStack.Peek(); element.Properties.Add(property); }
internal static object ParseStreamGeometry(BamlBinaryReader reader) { StringBuilder sb = new StringBuilder(); bool shouldClose = false; char lastChar = '\0'; while (true) { byte b = reader.ReadByte(); bool bit1 = (b & 0x10) == 0x10; bool bit2 = (b & 0x20) == 0x20; bool bit3 = (b & 0x40) == 0x40; bool bit4 = (b & 0x80) == 0x80; switch (b & 0xF) { case 0x0: //Begin { shouldClose = bit2; AddPathCommand('M', ref lastChar, sb); AddPathPoint(reader, sb, bit3, bit4); break; } case 0x1: //LineTo { AddPathCommand('L', ref lastChar, sb); AddPathPoint(reader, sb, bit3, bit4); break; } case 0x2: //QuadraticBezierTo { AddPathCommand('Q', ref lastChar, sb); AddPathPoint(reader, sb, bit3, bit4); AddPathPoint(reader, sb); break; } case 0x3: //BezierTo { AddPathCommand('C', ref lastChar, sb); AddPathPoint(reader, sb, bit3, bit4); AddPathPoint(reader, sb); AddPathPoint(reader, sb); break; } case 0x4: //PolyLineTo { bool isStroked = bit1; bool isSmooth = bit2; AddPathCommand('L', ref lastChar, sb); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) AddPathPoint(reader, sb); break; } case 0x5: //PolyQuadraticBezierTo { AddPathCommand('Q', ref lastChar, sb); int count = reader.ReadInt32(); //System.Diagnostics.Debug.Assert(count % 2 == 0); for (int i = 0; i < count; i++) AddPathPoint(reader, sb); break; } case 0x6: //PolyBezierTo { AddPathCommand('C', ref lastChar, sb); int count = reader.ReadInt32(); //System.Diagnostics.Debug.Assert(count % 3 == 0); for (int i = 0; i < count; i++) AddPathPoint(reader, sb); break; } case 0x7: //ArcTo { double endPtX = ReadPathDouble(reader, bit3); double endPtY = ReadPathDouble(reader, bit4); byte arcInfo = reader.ReadByte(); bool isLarge = (arcInfo & 0xF) != 0; bool clockWise = (arcInfo & 0xF0) != 0; double sizeX = reader.ReadCompressedDouble(); double sizeY = reader.ReadCompressedDouble(); double angle = reader.ReadCompressedDouble(); sb.AppendFormat("A {0},{1} {2} {3} {4} {5},{6} ", sizeX, sizeY, angle, isLarge ? 1 : 0, clockWise ? 1 : 0, endPtX, endPtY); lastChar = 'A'; break; } case 0x8: //Closed { if (shouldClose) { sb.Append("Z"); } else if (sb.Length > 0) { // trim off the ending space sb.Remove(sb.Length - 1, 0); } return sb.ToString(); } case 0x9: //FillRule { sb.Insert(0, bit1 ? "F1 " : "F0 "); lastChar = 'F'; break; } default: throw new InvalidOperationException(); } } }
private void ReadPropertyCustom(BamlBinaryReader reader) { Element element; short identifier = reader.ReadInt16(); short num2 = reader.ReadInt16(); bool flag = (num2 & 0x4000) == 0x4000; num2 = (short)(num2 & -16385); Property property = new Property(PropertyType.Value); property.PropertyDeclaration = this.GetPropertyDeclaration(identifier); switch (num2) { case 0x2e8: switch (reader.ReadByte()) { case 1: { uint argb = reader.ReadUInt32(); if (argb == 0xffffff) { property.Value = "Transparent"; } else { property.Value = KnownColors.KnownColorFromUInt(argb); } goto Label_038A; } case 2: property.Value = reader.ReadString(); goto Label_038A; } throw new NotSupportedException(); case 0x2e9: { using (StringWriter writer = new StringWriter()) { int num8; int num10; int num12; byte num6 = reader.ReadByte(); int num7 = reader.ReadInt32(); switch (num6) { case 1: num8 = 0; goto Label_01C9; case 2: num10 = 0; goto Label_0202; case 3: num12 = 0; goto Label_023C; case 4: throw new NotSupportedException(); default: throw new NotSupportedException(); } Label_0194: if (num8 != 0) { writer.Write(","); } int num9 = reader.ReadInt32(); writer.Write(num9.ToString()); if (num9 > num7) { goto Label_0250; } num8++; Label_01C9: if (num8 < num7) { goto Label_0194; } goto Label_0250; Label_01D6: if (num10 != 0) { writer.Write(","); } writer.Write(((int)reader.ReadByte()).ToString()); num10++; Label_0202: if (num10 < num7) { goto Label_01D6; } goto Label_0250; Label_020F: if (num12 != 0) { writer.Write(","); } writer.Write(((int)reader.ReadUInt16()).ToString()); num12++; Label_023C: if (num12 < num7) { goto Label_020F; } Label_0250: property.Value = writer.ToString(); goto Label_038A; } } case 0x2ea: property.Value = PathDataParser.ParseStreamGeometry(reader); goto Label_038A; case 0x2eb: case 0x2f0: { using (StringWriter writer3 = new StringWriter()) { int num18 = reader.ReadInt32(); for (int i = 0; i < num18; i++) { if (i != 0) { writer3.Write(" "); } for (int j = 0; j < 3; j++) { if (j != 0) { writer3.Write(","); } writer3.Write(reader.ReadCompressedDouble().ToString()); } } property.Value = writer3.ToString(); goto Label_038A; } } case 0x2ec: { using (StringWriter writer2 = new StringWriter()) { int num14 = reader.ReadInt32(); for (int k = 0; k < num14; k++) { if (k != 0) { writer2.Write(" "); } for (int m = 0; m < 2; m++) { if (m != 0) { writer2.Write(","); } writer2.Write(reader.ReadCompressedDouble().ToString()); } } property.Value = writer2.ToString(); goto Label_038A; } } case 0x2ed: case 750: case 0x2ef: goto Label_0384; case 0x89: { short num3 = reader.ReadInt16(); if (flag) { TypeDeclaration typeDeclaration = this.GetTypeDeclaration(num3); string name = reader.ReadString(); property.Value = new PropertyDeclaration(name, typeDeclaration); } else { property.Value = this.GetPropertyDeclaration(num3); } goto Label_038A; } case 0x2e: { int num4 = reader.ReadByte(); property.Value = (num4 == 1) ? "true" : "false"; goto Label_038A; } } Label_0384: throw new NotSupportedException(); Label_038A: element = (Element)this.elementStack.Peek(); element.Properties.Add(property); }