Change font face and size in Twine with Sugarcue

- Posted in Coding by

Thanks to Josh Grams, I now understand how to set up players/readers of my twines with the ability to change font face and font size. Below I link to the scripts you need to drop, respectively, into the javascript and stylesheet special passages in the desktop Twine 2.10.0 app. Here is the zip containing the needed JS and CSS. I host a demo of this here and here, and mention it in my Twine Tidbits on the local copy of my blog.

Font importation

- Posted in Uncategorized by

How to import a font into a C# program:

      //interop to allow import of game font
  [System.Runtime.InteropServices.DllImport("gdi32.dll")]
  private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont,
      IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts);

Also before the form's constructor, add a form-level variable (but make sure it comes after the Win32 function import):

Font myFont;

If you have the desired font as a .resx resource in your Visual Studio project, you'll use the following code inside the form's constructor:

//Form1 constructor code that pulls game font into memory
      byte[] fontData = Properties.Resources.brushstr;
      IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);
      System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
      uint dummy = 0;
      fonts.AddMemoryFont(fontPtr, Properties.Resources.brushstr.Length);
      AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.brushstr.Length, IntPtr.Zero, ref dummy);
      System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

      myFont = new Font(fonts.Families[0], 16.0F);

Import a font using c-sharp

- Posted in Coding by
using System.Runtime.InteropServices;

      //interop to allow import of game font
      [System.Runtime.InteropServices.DllImport("gdi32.dll")]
      private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont,
          IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts);

Also before the form's constructor, add a form-level variable (but make sure it comes after the Win32 function import):

Font myFont;

If you have the desired font as a .resx resource in your Visual Studio project, you'll use the following code inside the form's constructor:

//Form1 constructor code that pulls game font into memory
          byte[] fontData = Properties.Resources.brushstr;
          IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);
          System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
          uint dummy = 0;
          fonts.AddMemoryFont(fontPtr, Properties.Resources.brushstr.Length);
          AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.brushstr.Length, IntPtr.Zero, ref dummy);
          System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

          myFont = new Font(fonts.Families[0], 16.0F);