Microcode: PowerShell + XNA: New-SpriteFont
Synopsis:
Creates a New XNA SpriteFont
Syntax:
New-SpriteFont [[-font] [<Object>]] [[-size] [<Int32>]] [[-spacing] [<Int32>]] [[-style] [<Object>]] [<CommonParameters>]
Detailed Description:
Generates an XNA SpriteFont file. Allows you to specify the font name, size, spacing, style, and if kerning is used or not
Examples:
-------------------------- EXAMPLE 1 --------------------------
# Create a simple New sprite font
New-SpriteFont
-------------------------- EXAMPLE 2 --------------------------
# Create a sprite font using the font Garamond and a fontsize of 12
New-SpriteFont "Garamond" 12
Command Parameters:
| Name |
Description |
| font |
The font name of the XNA sprite font to use (default Lucida Console) |
| size |
The font size of the XNA Sprite Font (default 14) |
| spacing |
The spacing between the fonts (default 0) |
| useKerning |
If set, the XNA sprite font will use kerning |
| style |
The style of the font (e.g. Regular, Bold, Italic) |
Here's New-SpriteFont:
function New-SpriteFont {
<#
.Synopsis
Creates a New XNA SpriteFont
.Description
Generates an XNA SpriteFont file. Allows you to specify the font name, size, spacing, style, and if kerning is used or not
.Parameter font
The font name of the XNA sprite font to use (default Lucida Console)
.Parameter size
The font size of the XNA Sprite Font (default 14)
.Parameter spacing
The spacing between the fonts (default 0)
.Parameter useKerning
If set, the XNA sprite font will use kerning
.Parameter style
The style of the font (e.g. Regular, Bold, Italic)
.Link
Get-Font
.Example
# Create a simple New sprite font
New-SpriteFont
.Example
# Create a sprite font using the font Garamond and a fontsize of 12
New-SpriteFont "Garamond" 12
#>
param($font = "Lucida Console",
[int]$size = 14,
[int]$spacing = 0,
[switch]$useKerning,
$style = "Regular")
if (-not (Get-Command Get-Font -ErrorAction SilentlyContinue )) { throw $error[0] }
$checkedFont = Get-Font $font
if (-not $checkedFont) {
throw "The font name $font is not valid. Pick a new one a-hole."
}
@"
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<!--
Modify this string to change the font that will be imported.
-->
<FontName>$font</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>$size</Size>
<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>$spacing</Spacing>
<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>$($useKerning.ToString().ToLower())</UseKerning>
<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>$style</Style>
<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<!-- <DefaultCharacter>*</DefaultCharacter> -->
<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start> </Start>
<End>~</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>
"@
}
Automatically generated with Write-CommandBlogPost