Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.Override.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<_IncludeWindows></_IncludeWindows>
<_IncludeTizen></_IncludeTizen>
<_IncludeGtk>true</_IncludeGtk>
<_IncludeAndroid>true</_IncludeAndroid>
<_IncludeAndroid>false</_IncludeAndroid>
<_IncludeIos></_IncludeIos>
<_IncludeMacCatalyst></_IncludeMacCatalyst>
<_IncludeMacOS></_IncludeMacOS>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<_MauiBuildTasksLocation Condition="'$(_MauiBuildTasksLocation)' == ''">$(MSBuildThisFileDirectory).buildtasks\</_MauiBuildTasksLocation>
<_MauiAOTProfileLocation>$(MauiSrcDirectory)Controls\src\Build.Tasks\nuget\buildTransitive\netstandard2.0\</_MauiAOTProfileLocation>
<StrongNamerKeyFile>$(MauiRootDirectory)eng/microsoft.maui.controls.snk</StrongNamerKeyFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugType>portable</DebugType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down
3 changes: 3 additions & 0 deletions Microsoft.Maui.Gtk.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
"src\\BlazorWebView\\src\\Gtk\\Microsoft.AspNetCore.Components.WebView.Gtk.csproj",
"src\\BlazorWebView\\src\\Maui\\Microsoft.AspNetCore.Components.WebView.Maui.csproj",
"src\\Compatibility\\Core\\src\\Compatibility.csproj",
"src\\Controls\\Foldable\\src\\Controls.Foldable.csproj",
"src\\Controls\\Maps\\src\\Controls.Maps.csproj",
"src\\Controls\\samples\\Controls.Sample.Gtk\\Controls.Sample.Gtk.csproj",
"src\\Controls\\samples\\Controls.Sample\\Maui.Controls.Sample.csproj",
"src\\Controls\\src\\Build.Tasks\\Controls.Build.Tasks.csproj",
"src\\Controls\\src\\Core\\Controls.Core.csproj",
"src\\Controls\\src\\Xaml\\Controls.Xaml.csproj",
"src\\Core\\maps\\src\\Maps.csproj",
"src\\Core\\src\\Core.csproj",
"src\\Essentials\\src\\Essentials.csproj",
"src\\Graphics\\samples\\GraphicsTester.Gtk\\GraphicsTester.Gtk.csproj",
Expand Down
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" protocolVersion="3" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" protocolVersion="3" />
<add key="benchmark-dotnet-prerelease" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/benchmark-dotnet-prerelease/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<MicrosoftAspNetCoreMetadataPackageVersion>8.0.0</MicrosoftAspNetCoreMetadataPackageVersion>
<MicrosoftJSInteropPackageVersion>8.0.0</MicrosoftJSInteropPackageVersion>
<!-- Other packages -->
<MicrosoftCodeAnalysisNetAnalyzersVersion>8.0.0</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>9.0.0</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisPublicApiAnalyzersVersion>3.3.4</MicrosoftCodeAnalysisPublicApiAnalyzersVersion>
<MicrosoftCodeAnalysisBannedApiAnalyzersVersion>3.3.4</MicrosoftCodeAnalysisBannedApiAnalyzersVersion>
<SystemNumericsVectorsVersion>4.5.0</SystemNumericsVectorsVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(_MauiDotNetTfm);$(MauiPlatforms)</TargetFrameworks>
<TargetFrameworks>$(_MauiDotNetTfm)</TargetFrameworks>
<Nullable>enable</Nullable>
<DefineConstants>$(DefineConstants);WEBVIEW2_MAUI</DefineConstants>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"Controls.Sample.Gtk": {
"commandName": "Project"
},
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}
14 changes: 7 additions & 7 deletions src/Controls/samples/Controls.Sample/Maui.Controls.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<!--<PackageReference Include="Microsoft.Maui.Graphics.Skia" />-->
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
</ItemGroup>

<ItemGroup Condition=" '$(UseMaui)' != 'true' ">
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<!--<ItemGroup>
<ProjectReference
Include="..\..\..\Controls\src\Core\Controls.SourceGen.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
</ItemGroup>
</ItemGroup>-->

<ItemGroup>
<ProjectReference Include="..\..\..\BlazorWebView\samples\MauiRazorClassLibrarySample\MauiRazorClassLibrarySample.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"Windows Machine": {
"commandName": "MsixPackage",
"nativeDebugging": true
},
"WSL": {
"commandName": "WSL2",
"distributionName": "",
"environmentVariables": {
"DISPLAY": "127.0.0.1:0.0",
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}
27 changes: 5 additions & 22 deletions src/Core/src/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="WebkitGtkSharp" Version="3.24.24.95" />
<ProjectReference Include="..\..\Graphics\src\Graphics\Graphics.csproj" />
<PackageReference Include="System.Numerics.Vectors" Condition="$(TargetFramework.StartsWith('netstandard'))" />
</ItemGroup>
Expand Down Expand Up @@ -75,32 +76,14 @@

<Import Project="$(MauiRootDirectory)eng/ReplaceText.targets" />

<Target Name="_GenerateBundledVersions"
BeforeTargets="Build;AssignTargetPaths"
DependsOnTargets="SetVersions"
Inputs="$(MSBuildProjectFile);$(MauiRootDirectory)eng\Versions.props;nuget\buildTransitive\GtkSharp.Maui.Core.BundledVersions.in.targets"
Outputs="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets">
<Target Name="_GenerateBundledVersions" BeforeTargets="Build;AssignTargetPaths" DependsOnTargets="SetVersions" Inputs="$(MSBuildProjectFile);$(MauiRootDirectory)eng\Versions.props;nuget\buildTransitive\GtkSharp.Maui.Core.BundledVersions.in.targets" Outputs="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets">
<ItemGroup>
<_ValuesToReplace Include="VERSION" PropertyName="PackageReferenceVersion" />
</ItemGroup>
<Copy
SourceFiles="nuget\buildTransitive\GtkSharp.Maui.Core.BundledVersions.in.targets"
DestinationFiles="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets"
/>
<ReplaceText
Input="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets"
Output="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets"
OldValue="@%(_ValuesToReplace.Identity)@"
NewValue="$(%(_ValuesToReplace.PropertyName))"
/>
<Copy SourceFiles="nuget\buildTransitive\GtkSharp.Maui.Core.BundledVersions.in.targets" DestinationFiles="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets" />
<ReplaceText Input="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets" Output="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets" OldValue="@%(_ValuesToReplace.Identity)@" NewValue="$(%(_ValuesToReplace.PropertyName))" />
<ItemGroup>
<None
Include="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets"
Link="nuget\buildTransitive\GtkSharp.Maui.Core.BundledVersions.targets"
Pack="true"
PackagePath="buildTransitive"
Visible="false"
/>
<None Include="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets" Link="nuget\buildTransitive\GtkSharp.Maui.Core.BundledVersions.targets" Pack="true" PackagePath="buildTransitive" Visible="false" />
<FileWrites Include="$(IntermediateOutputPath)GtkSharp.Maui.Core.BundledVersions.targets" />
</ItemGroup>
</Target>
Expand Down
84 changes: 79 additions & 5 deletions src/Core/src/Fonts/EmbeddedFontLoader.Gtk.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,95 @@
using System;
using System.IO;
using System.Linq;
using Cairo;
using Microsoft.Maui.GtkInterop;
using Pango;
using Path = System.IO.Path;

namespace Microsoft.Maui
{
public partial class EmbeddedFontLoader
{
public string? LoadFont(EmbeddedFont font)
{
// gtk has no methods to load fonts
// see: http://mces.blogspot.com/2015/05/how-to-use-custom-application-fonts.html
var cfg = DllImportFontConfig.FcConfigGetCurrent();
if (cfg == IntPtr.Zero)
{
cfg = DllImportFontConfig.FcInitLoadConfigAndFonts();
DllImportFontConfig.FcConfigSetCurrent(cfg);
}

throw new NotImplementedException();
RegisterFromStream(font.ResourceStream!, font.FontName!, cfg);
DllImportFontConfig.PangoFcFontMapConfigChanged();

// freetype is needed. look at:
// https://github.com/Robmaister/SharpFont
// For debugging: list all active fonts
// var fonts = DllImportFontConfig.ListActiveFonts();
// GetPangoCairoFonts();

return font.FontName;
}

/// <summary>
/// Registers a font from the specified stream into the font configuration.
/// </summary>
/// <remarks>This method reads the font data from the provided stream, writes it to a temporary file, and
/// registers the file with the specified font configuration. The temporary file is created in the system's temporary
/// directory and will persist for the duration of the application's execution.</remarks>
/// <param name="fontStream">The <see cref="Stream"/> containing the font data. The stream must be readable.</param>
/// <param name="filename">The name of the font file, including its extension. This is used to determine the font type and generate a
/// temporary file.</param>
/// <param name="cfg">A handle to the font configuration object where the font will be registered.</param>
/// <exception cref="InvalidOperationException">Thrown if the font cannot be added to the font configuration.</exception>
static void RegisterFromStream(Stream fontStream, string filename, nint cfg)
{
var extension = Path.GetExtension(filename).ToLowerInvariant();
var pureFilename = Path.GetFileNameWithoutExtension(filename);

// Stream → byte[]
byte[] bytes;
if (fontStream is MemoryStream ms && ms.TryGetBuffer(out var seg))
{
bytes = seg.Array is null ? ms.ToArray() : seg.Array.AsSpan(seg.Offset, seg.Count).ToArray();
}
else
{
using var tmp = new MemoryStream();
fontStream.CopyTo(tmp);
bytes = tmp.ToArray();
}

var baseDir = Path.Combine(Path.GetTempPath(), "maui-app-fonts");
Directory.CreateDirectory(baseDir);
var tempPath = Path.Combine(baseDir, filename);

if (!File.Exists(tempPath))
File.WriteAllBytes(tempPath, bytes);

bool ok = DllImportFontConfig.FcConfigAppFontAddFile(cfg, tempPath);
if (!ok)
throw new InvalidOperationException($"FcConfigAppFontAddFile fehlgeschlagen: {tempPath}");
}

static FontFamily[] GetPangoCairoFonts(bool writeOutput = true)
{
using var surf = new ImageSurface(Format.ARGB32, 1, 1);
using var cr = new Cairo.Context(surf);
using var layout = CairoHelper.CreateLayout(cr);

var fontMap = layout.Context.FontMap;
var families = fontMap.Families;

if (writeOutput)
{
foreach (var family in families)
{
Console.WriteLine(family.Name);
foreach (var face in family.Faces)
Console.WriteLine($" - {face.FaceName} ({face.Describe()})");
}
}

return families;
}
}
}
68 changes: 13 additions & 55 deletions src/Core/src/Fonts/FontManager.Gtk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,7 @@
using static Microsoft.Maui.GtkInterop.DllImportFontConfig;

namespace Microsoft.Maui
{

// see: https://docs.gtk.org/Pango/struct.FontDescription.html
/*
public enum Pango.Weight
{
Thin = 100, // 0x00000064
Ultralight = 200, // 0x000000C8
Light = 300, // 0x0000012C
Semilight = 350, // 0x0000015E
Book = 380, // 0x0000017C
Normal = 400, // 0x00000190
Medium = 500, // 0x000001F4
Semibold = 600, // 0x00000258
Bold = 700, // 0x000002BC
Ultrabold = 800, // 0x00000320
Heavy = 900, // 0x00000384
Ultraheavy = 1000, // 0x000003E8
}

public enum Stretch
{
UltraCondensed,
ExtraCondensed,
Condensed,
SemiCondensed,
Normal,
SemiExpanded,
Expanded,
ExtraExpanded,
UltraExpanded,
}


public enum Style { Normal, Oblique, Italic }

public enum Variant
{
Normal,
SmallCaps,
}

public enum Gravity
{
South,
East,
North,
West,
Auto,
}

*/

{
public class FontManager : IFontManager
{

Expand All @@ -85,8 +33,18 @@ public FontDescription DefaultFontFamily

public double DefaultFontSize => _defaultFontSize ??= DefaultFontFamily?.GetSize() ?? 0;

public FontDescription GetFontFamily(Font font) =>
font == default ? SystemContext.FontDescription : font.ToFontDescription();
public FontDescription GetFontFamily(Font font)
{
if (font != default)
{
if(!string.IsNullOrWhiteSpace(font.Family)) _fontRegistrar.GetFont(font.Family);
return font.ToFontDescription();
}
else
{
return SystemContext.FontDescription;
}
}

public double GetFontSize(Font font)
{
Expand Down
32 changes: 31 additions & 1 deletion src/Core/src/Fonts/FontRegistrar.Gtk.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
#nullable enable

using System.IO;

namespace Microsoft.Maui
{
public partial class FontRegistrar : IFontRegistrar
{
string? LoadNativeAppFont(string font, string filename, string? alias) => null;
string? LoadNativeAppFont(string font, string filename, string? alias)
{
if(GtkBuildSettings.MauiFontBehavior == GtkBuildSettings.MauiResourceBehavior.EmbedFiles)
{
var (assembly, resourceName) = Storage.FileSystemUtils.GetMauiRessource(Storage.FileSystemUtils.MauiResourceType.MauiFont, filename);

var stream = assembly.GetManifestResourceStream(resourceName);

if(stream == null)
throw new FileNotFoundException($"Embedded font with the name {filename} was not found.");

return LoadEmbeddedFont(font, filename, alias, stream);
}
else
{
using var stream = GetNativeFontStream(filename, alias);

return LoadEmbeddedFont(font, filename, alias, stream);
}
}

static FileStream GetNativeFontStream(string filename, string? alias)
{
var fontPath = Storage.FileSystemUtils.GetFilePath(Storage.FileSystemUtils.MauiResourceType.MauiFont, filename);
if (File.Exists(fontPath))
return File.OpenRead(fontPath);

throw new FileNotFoundException($"Native font with the name {filename} was not found.");
}
}
}
Loading