How to install fonts?

Oct 24, 2015 at 7:55 PM
I could not find an example.

I attempt the following:
 var project = new Project("MyProgram",
                new Dir(@"%ProgramFiles%\My Company, Inc.\MyProgram",
                new Files(@"C:\Users\ddavi\Documents\Visual Studio 2015\Projects\MyProgram\Test\bin\debug\*.dll"),
                new File(@"C:\Users\ddavi\Documents\Visual Studio 2015\Projects\MyProgram\Test\bin\Debug\MyProgram.exe")),
                new Dir(@"%FontsFolder%", new File(@"C:\Windows\Fonts\Roboto-Bold.ttf")));
The program installs fine, but I do not see the font being installed even after rebooting the machine. In Wix you have to specify that the font file is truetype, etc. I do not see an option for such a thing? What is the correct way to install a font through wixsharp?
Coordinator
Oct 25, 2015 at 4:23 AM
I don't think installing the font requires you to pot it into the Fonts folder. Quick googling indicated that it is only a matter indicating that the file being installed is a font file. In Wix# it is achieved via additions attribute definition:
new File(@"C:\Windows\Fonts\Roboto-Bold.ttf") { AttributesDefinition="TrueType=yes"},
Please let me know if this simple change addresses the issue and I will update the samples to reflect "Font installation" scenario.
Oct 25, 2015 at 6:52 PM
Edited Oct 25, 2015 at 6:54 PM
Thanks for the reply Oleg.

I've now tried your suggestion (file by itself with an attributesdefinition) as well as keeping the %FontsFolder% directory with the aforementioned file with attribute, neither of which have successfully installed a font.

In the wix source file that was generated by wix#, it translated to the following (just the file by itself with attributesdefinition):
 <Component Id="Component.Roboto-Bold.ttf" Guid="6f330b47-2577-43ad-9095-1861186d24b2">
              <File Id="Roboto-Bold.ttf" Source="..\..\..\..\..\..\..\..\..\Windows\Fonts\Roboto-Bold.ttf" TrueType="yes" />
            </Component>
My other setup project where I successfully install a font file ( straight wix, not wix#), has the following:
 <DirectoryRef Id="FontsFolder">
      <Component Id="InstallFonts" Guid="{1C3139F1-C745-45D9-820D-68ABD9EBD48F}">
        <File Id="RobotoLight.TTF" Source="C:\Windows\Fonts\Roboto-Light.ttf" TrueType="yes" />
      </Component>
    </DirectoryRef>
Are the extra "........\" that show up in the source location for the font generated by wix# the culprit?

Thanks
David
Oct 26, 2015 at 1:16 AM
Oleg,

I hooked onto the WixSourceGenerated event and modified the XDocument file to correct the font source to Source="C:\Windows\Fonts\Roboto-Light.ttf" from Source="..................\Windows\Fonts\Roboto-Light.ttf". This corrected the issue, the font installed correctly once this was done. Perhaps a bug?
Coordinator
Oct 26, 2015 at 6:17 AM
No, the path cannot be the cause of the problem. If it was then candle would complain that the file could not be found.

I actually managed to test it and found that the solution works. I even updated the code with a specialized class FontFile and the corresponding sample (you can get it from here: "https://wixsharp.codeplex.com/SourceControl/latest#src/WixSharp.Samples/Wix# Samples/Install Font/setup.cs"). The whole working sample is as follows:
static public void Main()
{
    var project =
        new Project("MyProduct",
            new Dir(@"%ProgramFiles%\My Company\My Product",
                new File("readme.txt")),
            new Dir("%Fonts%", 
                new FontFile("FreeSansBold.ttf")));
        
                //The same can be achieved with File and custom attributes
                //new File("FreeSansBold.ttf") { AttributesDefinition="TrueType=yes"}));

    project.UI = WUI.WixUI_ProgressOnly;
    project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");
    project.PreserveTempFiles = true;

    project.BuildMsi();
}
Note that you don't have to use FontFile and you can use extra attributes with the File class.

The sample installs the test font properly:
Image
Coordinator
Oct 26, 2015 at 7:11 AM
Edited Oct 26, 2015 at 7:12 AM
> I hooked onto the WixSourceGenerated event and modified the XDocument file to correct the font source to Source="C:\Windows\Fonts\Roboto-Light.ttf" from Source="..................\Windows\Fonts\Roboto-Light.ttf". This corrected the issue, the font installed correctly once this was done. Perhaps a bug?
I only noticed this post.

You don't have to resort to WixSourceGenerated when relative path is a challenge. You can place the full path directly to the file constructor. I know it seems that it didn't work in your case but when I modified the code sample to include one of the system fonts like this:
new Dir("%Fonts%", 
    new File(@"C:\Windows\Fonts\yuminl.ttf")
It actually preserved the path as expected:
<Component Id="Component.yuminl.ttf" Guid="6f330b47-2577-43ad-9095-18616b080af8">
  <File Id="yuminl.ttf" Source="C:\Windows\Fonts\yuminl.ttf" />
</Component>
Thus I am not sure about the cause of that conversion to the relative path in your sample.
Oct 27, 2015 at 1:15 AM
Edited Oct 27, 2015 at 1:28 AM
I ran your example on wix# 1.0.28 binary, with only a modification of what font file it will use and I used the attributesdefinition version rather than FontFile (since its not in my version):
static public void Main()
{
 var project =
                new Project("MyProduct",
                    new Dir(@"%ProgramFiles%\My Company\My Product",
                        new File("readme.txt")),
                    new Dir("%Fonts%",
                        new File(@"C:\Windows\Fonts\Roboto-Light.ttf") {AttributesDefinition = "TrueType=yes"}));

            project.UI = WUI.WixUI_ProgressOnly;
            project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");
            project.PreserveTempFiles = true;


            project.WixSourceGenerated += ProjectOnWixSourceGenerated;
            var path = project.BuildMsi();
}
The following was generated... still has the relative directory all screwy.
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="6f330b47-2577-43ad-9095-1861ca25889c" Name="MyProduct" Language="1033" Codepage="Windows-1252" Version="1.0.0.0" UpgradeCode="6f330b47-2577-43ad-9095-1861ba25889b" Manufacturer="ddavi">
    <Package InstallerVersion="200" Compressed="yes" SummaryCodepage="Windows-1252" Languages="1033" />
    <Media Id="1" Cabinet="MyProduct.cab" EmbedCab="yes" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="ProgramFilesFolder">
        <Directory Id="ProgramFilesFolder.My_Company" Name="My Company">
          <Directory Id="INSTALLDIR" Name="My Product">
            <Component Id="Component.readme.txt" Guid="6f330b47-2577-43ad-9095-18615e463af3">
              <File Id="readme.txt" Source="readme.txt" />
            </Component>
          </Directory>
        </Directory>
      </Directory>
      <Directory Id="FontsFolder" Name="FontsFolder">
        <Component Id="Component.Roboto_Light.ttf" Guid="6f330b47-2577-43ad-9095-18617fbcbe58">
          <File Id="Roboto_Light.ttf" Source="..\..\..\..\..\..\..\..\..\Windows\Fonts\Roboto-Light.ttf" TrueType="yes" />
        </Component>
      </Directory>
    </Directory>
    <Feature Id="Complete" Title="Complete" Absent="allow" Level="1">
      <ComponentRef Id="Component.readme.txt" />
      <ComponentRef Id="Component.Roboto_Light.ttf" />
    </Feature>
  </Product>
</Wix>
I am not sure what is causing the differences between you and I but I immensely appreciate your help. I am able to overcome this challenge with modifying the wix file as I did before, but there must be a bigger problem somewhere that is causing the need for me to do that in the first place.

But of course, in actual deployment I wouldn't want to rely on the system fonts folder to provide the font (since not every developer may have the same fonts installed), so I will include it with the setup/builder project and see if that functions. I'll let you know.. thanks.
Oct 27, 2015 at 1:50 AM
Oleg,

I just tried it with my font added as file to my project (so it shows up in my debug folder), the wix source generated made sense for the path and it installed correctly to my virtual box. I am still not sure why the fonts folder path does not work correctly, but that wouldn't be a very smart way to go about it in the first place... it was just the easiest to do to demo the wix# package.
Coordinator
Oct 29, 2015 at 12:12 AM
OK I think I know the cause for the discrepancy in the wxs code generation on your and my machines. My build script is located on a non-system partition thus the paths cannot be converted in relative and the compiler falls back to the absolute paths. However in your case most likely you are running your script from the system partition (c:\ drive) and the font directory from the same partition is resolved into relative path as expected. This default behavior can be overwritten with Compiler.EmitRelativePaths = false;.

This is what I did for further testing. I just created the project from VS WixSharp template and only added a single line of code without even modifying the project items:
var project =
    new Project("MyProduct",
        new Dir(@"%ProgramFiles%\My Company\My Product",
            new File("readme.txt")),
         //next is the new test code
         new Dir("%Fonts%", new FontFile(@"C:\Windows\Fonts\arial.ttf")));
This code emits (as it should) relative paths"
<Component Id="Component.arial.ttf" Guid="6fe30b47-2577-43ad-9095-186133ca6a46">
    <File Id="arial.ttf" Source="..\..\..\..\..\..\..\Windows\Fonts\arial.ttf" TrueType="yes" />
</Component>
Though in my case this relative path is a correct one. Thus the following simple check from the script:
Console.WriteLine("Path test: " + System.IO.Path.GetFullPath(@"..\..\..\..\..\..\..\Windows\Fonts\arial.ttf"));
project.BuildMsi();
Yields the expected output:
------ Build started: Project: WixSharp Setup12, Configuration: Debug Any CPU ------
  WixSharp Setup12 -> C:\Users\<user>\Documents\Visual Studio 2015\Projects\WixSharp Setup12\WixSharp Setup12\bin\Debug\WixSharp Setup.exe
  Building MSI
  Path test: C:\Windows\Fonts\arial.ttf
All this means that there is no obvious reason for the emitted relative path on your PC to be wrong so let's verify that it is indeed wrong. Can you please put the same path test in your code and verify the output?

I agree, the production build will have to source the font file not from the Fonts folder but from the source control thus you are not affected by this problem. But I really want to see what causes (if indeed it does) the error in your environment as it may indicate the actual problem with the compiler.

Thank you
Oct 29, 2015 at 1:24 AM
Edited Oct 29, 2015 at 2:23 PM
Hello Oleg,

Using the relative path that it would generate on my computer,
"..\..\..\..\..\..\..\..\..\Windows\Fonts\arial.ttf"
the path test came up with the following:

Path test: C:\Windows\Fonts\arial.ttf

So... that does seem to be working. When I had originally composed this email I used the relative path you provided in your last post on accident, and got a weird path as a result (understandably so).

Hmm...