public void TestSplitComplex() { // Test with a Document that already has a shared style to make // sure it's not disturbed. Also check with a Placemark that // doesn't have a style. const string InputKml = "<Document>" + "<StyleMap id='stylemap0'/>" + "<Placemark><name>no style</name></Placemark>" + "<Placemark>" + "<Style><LineStyle/></Style>" + "</Placemark>" + "<Placemark>" + "<name>has shared stylemap</name>" + "<styleUrl>#stylemap0</styleUrl>" + "</Placemark>" + "</Document>"; const string ExpectedKml = "<Document>" + "<StyleMap id='stylemap0'/>" + "<Style id='_0'><LineStyle/></Style>" + "<Placemark><name>no style</name></Placemark>" + "<Placemark><styleUrl>#_0</styleUrl></Placemark>" + "<Placemark>" + "<name>has shared stylemap</name>" + "<styleUrl>#stylemap0</styleUrl>" + "</Placemark>" + "</Document>"; CompareText(InputKml, ExpectedKml, e => StyleResolver.SplitStyles(e)); }
public void TestInlineStyleUrl() { var placemark = new Placemark { StyleUrl = new Uri("http://example.com/style.kml#cool-style") }; Placemark output = StyleResolver.InlineStyles(placemark); Assert.That(output.StyleUrl, Is.EqualTo(placemark.StyleUrl)); placemark.StyleUrl = new Uri("#non-existent-local-reference", UriKind.Relative); output = StyleResolver.InlineStyles(placemark); Assert.That(output.StyleUrl, Is.EqualTo(placemark.StyleUrl)); var document = new Document(); document.AddStyle(new Style { Id = "non-existent-local-reference" }); document.AddFeature(placemark); document = StyleResolver.InlineStyles(document); placemark = (Placemark)document.Features.ElementAt(0); Assert.That(placemark.StyleUrl, Is.Null); }
public void TestSplitNoDocument() { // Make sure if there's no document then it's unaltered. const string Kml = "<Folder>" + "<name>f</name>" + "<Placemark>" + "<Style><IconStyle/></Style>" + "</Placemark>" + "</Folder>"; CompareText(Kml, Kml, e => StyleResolver.SplitStyles(e)); // Input and the output should be the same }
public static void Run() { KmlFile file = Program.OpenFile("Enter a file to inline the styles:"); if (file == null) { return; } var inlined = StyleResolver.InlineStyles(file.Root); var serializer = new Serializer(); serializer.Serialize(inlined); Console.WriteLine(serializer.Xml); }
public void TestInlineComplex() { using (Stream data = SampleData.CreateStream("Engine.Data.Style Data.kml")) using (Stream output = SampleData.CreateStream("Engine.Data.Style Output.kml")) { var parser = new Parser(); parser.Parse(data); Document actual = GetDocument((Document)(((Kml)parser.Root).Feature), "InlineStylesTest"); parser.Parse(output); Document expected = GetDocument((Document)(((Kml)parser.Root).Feature), "InlineStylesTest"); actual = StyleResolver.InlineStyles(actual); SampleData.CompareElements(expected, actual); } }
void ArrangeRoot() { StyleResolver.Revalidate(); if (StyleResolver.StyleRules.Count == 0) { throw new InvalidOperationException("The style system contains no style-rules. This will result in errors. Aborting!"); } var screenSpace = Bounds; if (lastLayoutSize != screenSpace || Root.LayoutInvalid) { Root.InvalidateLayout(); Root.Arrange(screenSpace); lastLayoutSize = screenSpace; } }
public void TestSplitBasic() { const string InputKml = "<Document>" + "<Placemark>" + "<Style/>" + "</Placemark>" + "</Document>"; const string ExpectedKml = "<Document>" + "<Style id='_0'/>" + "<Placemark>" + "<styleUrl>#_0</styleUrl>" + "</Placemark>" + "</Document>"; CompareText(InputKml, ExpectedKml, e => StyleResolver.SplitStyles(e)); }
public void TestSplitUniqueId() { // Force a collision and make sure it overwrites the id const string InputKml = "<Document>" + "<Style id='_0'/>" + "<Placemark><Style id='my_id'/></Placemark>" + "</Document>"; const string ExpectedKml = "<Document>" + "<Style id='_0'/>" + "<Style id='_1'/>" + "<Placemark>" + "<styleUrl>#_1</styleUrl>" + "</Placemark>" + "</Document>"; CompareText(InputKml, ExpectedKml, e => StyleResolver.SplitStyles(e)); }
public void TestInlineUpdate() { var document = new Document(); document.AddStyle(new Style { Id = "style0" }); var create = new CreateCollection { document }; var update = new Update(); update.AddUpdate(create); Update output = StyleResolver.InlineStyles(update); // Make sure it didn't change anything SampleData.CompareElements(update, output); }
public void TestInlineBasic() { // Build our Kml with a shared style const string InputKml = "<Document>" + "<Style id='_0' />" + "<Placemark>" + "<styleUrl>#_0</styleUrl>" + "</Placemark>" + "</Document>"; const string ExpectedKml = "<Document>" + "<Placemark>" + "<StyleMap>" + "<Pair><key>normal</key><Style/></Pair>" + "<Pair><key>highlight</key><Style/></Pair>" + "</StyleMap>" + "</Placemark>" + "</Document>"; CompareText(InputKml, ExpectedKml, e => StyleResolver.InlineStyles(e)); }
private static void RunTestCase(Document data, string id, StyleState state, Style expected) { var file = KmlFile.Create(data, true); var feature = file.FindObject(id) as Feature; Assert.That(feature, Is.Not.Null); // Make sure the test data is ok Style style = StyleResolver.CreateResolvedStyle(feature, file, state); if (expected == null) { // Make sure everything is null Assert.That(style.Balloon, Is.Null); Assert.That(style.Icon, Is.Null); Assert.That(style.Label, Is.Null); Assert.That(style.Line, Is.Null); Assert.That(style.List, Is.Null); Assert.That(style.Polygon, Is.Null); } else { SampleData.CompareElements(expected, style); } }
public UIStyle(IContentLoader contentLoader) { StyleSystem = new StyleSystem(contentLoader); StyleResolver = new StyleResolver(StyleSystem); }
public virtual void Resolve(StyleResolver <StyleData> resolver) { // noop }