Bläddra i källkod

res support finished

Benedikt Schroeder 7 år sedan
förälder
incheckning
756db86316
2 ändrade filer med 15 tillägg och 25 borttagningar
  1. 5 5
      samples/ControlCatalog/Pages/BorderPage.xaml
  2. 10 20
      src/Avalonia.Visuals/Media/FontFamily.cs

+ 5 - 5
samples/ControlCatalog/Pages/BorderPage.xaml

@@ -26,11 +26,11 @@
               CornerRadius="8"
               Padding="16">
                 <StackPanel>
-                    <TextBlock FontFamily="resm:ControlCatalog.Fonts?assembly=ControlCatalog#Pixel Operator">Rounded Corners</TextBlock>
-                    <TextBlock FontFamily="resm:ControlCatalog.Fonts?assembly=ControlCatalog#Pixel Operator" FontWeight="Bold">Rounded Corners</TextBlock>
-                    <TextBlock FontFamily="resm:ControlCatalog.Fonts.Aspergit*.ttf?assembly=ControlCatalog#Aspergit" FontWeight="Bold">Rounded Corners</TextBlock>
-                    <TextBlock FontFamily="resm:ControlCatalog.Fonts.Aspergit*.ttf?assembly=ControlCatalog#Aspergit" FontWeight="Bold" FontStyle="Italic">Rounded Corners</TextBlock>
-                    <TextBlock FontFamily="resm:ControlCatalog.Fonts.Aspergit*.ttf?assembly=ControlCatalog#Aspergit" FontStyle="Italic">Rounded Corners</TextBlock>
+                    <TextBlock FontFamily="res:/Fonts?assembly=ControlCatalog#Pixel Operator">Rounded Corners</TextBlock>
+                    <TextBlock FontFamily="res:/Fonts?assembly=ControlCatalog#Pink Highway" FontWeight="Bold">Rounded Corners</TextBlock>
+                    <TextBlock FontFamily="res:/Fonts/Aspergit*.ttf?assembly=ControlCatalog#Aspergit" FontWeight="Bold">Rounded Corners</TextBlock>
+                    <TextBlock FontFamily="res:/Fonts/Aspergit*.ttf?assembly=ControlCatalog#Aspergit" FontWeight="Bold" FontStyle="Italic">Rounded Corners</TextBlock>
+                    <TextBlock FontFamily="res:/Fonts/Aspergit*.ttf?assembly=ControlCatalog#Aspergit" FontStyle="Italic">Rounded Corners</TextBlock>
                 </StackPanel>
             </Border>
         </StackPanel>

+ 10 - 20
src/Avalonia.Visuals/Media/FontFamily.cs

@@ -44,19 +44,18 @@ namespace Avalonia.Media
         {
             if (source.AbsolutePath.Contains(".ttf"))
             {
-                var filePathWithoutExtension = source.AbsolutePath.Replace(".ttf", "");
-
-                if (source.Scheme == "resm")
+                if (source.Scheme == "res")
+                {
+                    FileName = source.AbsolutePath.Split('/').Last();
+                }
+                else
                 {
+                    var filePathWithoutExtension = source.AbsolutePath.Replace(".ttf", "");
                     var fileNameWithoutExtension = filePathWithoutExtension.Split('.').Last();
                     FileName = fileNameWithoutExtension + ".ttf";
-                    Location = new Uri(source.OriginalString.Replace("." + FileName, ""), UriKind.RelativeOrAbsolute);
                 }
 
-                if (source.Scheme == "res")
-                {
-                    FileName = source.AbsolutePath.Split('/').Last();
-                }
+                Location = new Uri(source.OriginalString.Replace("." + FileName, ""), UriKind.RelativeOrAbsolute);
             }
             else
             {
@@ -202,7 +201,7 @@ namespace Avalonia.Media
         {
             var assembly = GetAssembly(location);
 
-            var compareTo = fileName.Split('*').First();
+            var compareTo = GetLocationPath(location) + fileName.Split('*').First();
 
             var matchingResources = assembly.Resources.Where(x => x.Contains(compareTo));
 
@@ -218,18 +217,9 @@ namespace Avalonia.Media
         {
             if (uri.Scheme == "resm") return uri.AbsolutePath;
 
-            var path = new StringBuilder();
-
-            for (var index = 0; index < uri.Segments.Length; index++)
-            {
-                path.Append(uri.Segments[index]);
-                if (index < uri.Segments.Length - 1)
-                {
-                    path.Append('.');
-                }
-            }
+            var path = uri.AbsolutePath.Replace("/", ".");
 
-            return path.ToString();
+            return path;
         }
 
         private AssemblyDescriptor GetAssembly(Uri uri)