本文整理汇总了C#中System.Drawing.Text.PrivateFontCollection类的典型用法代码示例。如果您正苦于以下问题:C# PrivateFontCollection类的具体用法?C# PrivateFontCollection怎么用?C# PrivateFontCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrivateFontCollection类属于System.Drawing.Text命名空间,在下文中一共展示了PrivateFontCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterFont
/// <summary>
/// Installs font on the user's system and adds it to the registry so it's available on the next session
/// Your font must be included in your project with its build path set to 'Content' and its Copy property
/// set to 'Copy Always'
/// </summary>
/// <param name="contentFontName">Your font to be passed as a resource (i.e. "myfont.tff")</param>
private static void RegisterFont(string contentFontName)
{
DirectoryInfo dirWindowsFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));
// Concatenate Fonts folder onto Windows folder.
string strFontsFolder = Path.Combine(dirWindowsFolder.FullName, "Fonts");
// Creates the full path where your font will be installed
var fontDestination = Path.Combine(strFontsFolder, contentFontName);
if (!File.Exists(fontDestination))
{
// Copies font to destination
System.IO.File.Copy(Path.Combine(System.IO.Directory.GetCurrentDirectory(), contentFontName), fontDestination);
// Retrieves font name
// Makes sure you reference System.Drawing
PrivateFontCollection fontCol = new PrivateFontCollection();
fontCol.AddFontFile(fontDestination);
var actualFontName = fontCol.Families[0].Name;
//Add font
AddFontResource(fontDestination);
//Add registry entry
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",
actualFontName, contentFontName, RegistryValueKind.String);
}
}
示例2: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
byte[] fontArray = Properties.Resources.OpenSans_ExtraBold;
int dataLength = Properties.Resources.OpenSans_ExtraBold.Length;
// ASSIGN MEMORY AND COPY BYTE[] ON THAT MEMORY ADDRESS
IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
Marshal.Copy(fontArray, 0, ptrData, dataLength);
uint cFonts = 0;
AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);
PrivateFontCollection pfc = new PrivateFontCollection();
//PASS THE FONT TO THE PRIVATEFONTCOLLECTION OBJECT
pfc.AddMemoryFont(ptrData, dataLength);
//FREE THE "UNSAFE" MEMORY
Marshal.FreeCoTaskMem(ptrData);
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
Font font = new Font(pfc.Families[0], Font.Size, FontStyle.Regular);
e.Graphics.DrawString(Text, font, new SolidBrush(this.ForeColor), new PointF(20, 17), format);
}
示例3: Form1
public Form1()
{
InitializeComponent();
rand = new Random();
dataGrid = new Grid("TileMap.csv");
Controls.Add(dataGrid);
sound = new System.Windows.Media.MediaPlayer();
sound.Open(new Uri("pacmanDubHeavy.mp3", UriKind.Relative));
sound.Play();
gameEngine = new GameEngine(dataGrid, rand, timer1.Interval);
//pacman font
PrivateFontCollection fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile("crackman.ttf");
FontFamily ff = fontCollection.Families[0];
int fontsize = 12;
Font pacmanFont = new Font(ff, fontsize, FontStyle.Bold);
label2.Font = pacmanFont;
label3.Font = pacmanFont;
label4.Font = pacmanFont;
lifeCounter = new PictureBox[3];
lifeCounter[0] = pictureBox1;
lifeCounter[1] = pictureBox2;
lifeCounter[2] = pictureBox3;
}
示例4: Intro
public Intro()
{
InitializeComponent();
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile("..\\..\\TrajanPro-Regular.ttf");
label1.Font = new Font(pfc.Families[0], 10, FontStyle.Bold);
}
示例5: Intitial
/// <summary>
/// 初始化
/// </summary>
public void Intitial( FontMgr.FontLoadInfo fontLoadInfo )
{
try
{
privateFontCollection = new PrivateFontCollection();
foreach (FontMgr.FontInfo info in fontLoadInfo.UnitCodeFontInfos)
{
privateFontCollection.AddFontFile( info.path );
}
fontFamilys = privateFontCollection.Families;
if (fontFamilys.Length != fontLoadInfo.UnitCodeFontInfos.Count)
throw new Exception( "导入的各个字体必须属于不同类别" );
for (int i = 0; i < fontFamilys.Length; i++)
{
fonts.Add( fontLoadInfo.UnitCodeFontInfos[i].name, new System.Drawing.Font( fontFamilys[i], fontLoadInfo.DefualtEmSize ) );
}
System.Drawing.Bitmap tempBitMap = new System.Drawing.Bitmap( 1, 1 );
mesureGraphics = System.Drawing.Graphics.FromImage( tempBitMap );
}
catch (Exception)
{
throw new Exception( "读取字体文件出错" );
}
}
示例6: LoadFonts
private static void LoadFonts(PrivateFontCollection fonts, string folderPath, bool recursive = true)
{
if (!Directory.Exists(folderPath))
return;
foreach (var item in Directory.GetFiles(folderPath, "*.*tf"))
{
string ext = Path.GetExtension(item);
if (string.IsNullOrEmpty(ext) || ext.Length != 4)
continue;
try
{
fonts.AddFontFile(item);
}
catch(Exception ex)
{
Logging.LogManagerProvider.Instance.WriteError(ex, string.Format("Font '{0}' can not be loaded", item));
}
}
if (!recursive)
return;
foreach (var subdir in Directory.GetDirectories(folderPath))
LoadFonts(fonts, subdir, recursive);
}
示例7: Dispose_Family
public void Dispose_Family ()
{
PrivateFontCollection pfc = new PrivateFontCollection ();
pfc.Dispose ();
Assert.IsNotNull (pfc.Families);
// no it's not a ObjectDisposedException
}
示例8: QFont
public QFont(string fileName, float size, FontStyle style, QFontBuilderConfiguration config)
{
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile(fileName);
var fontFamily = pfc.Families[0];
if (!fontFamily.IsStyleAvailable(style))
throw new ArgumentException("Font file: " + fileName + " does not support style: " + style );
if (config == null)
config = new QFontBuilderConfiguration();
TransformViewport? transToVp = null;
float fontScale = 1f;
if (config.TransformToCurrentOrthogProjection)
transToVp = OrthogonalTransform(out fontScale);
using(var font = new Font(fontFamily, size * fontScale * config.SuperSampleLevels, style)){
fontData = BuildFont(font, config, null);
}
if (config.ShadowConfig != null)
Options.DropShadowActive = true;
if (transToVp != null)
Options.TransformToViewport = transToVp;
if(config.UseVertexBuffer)
InitVBOs();
}
示例9: FontCollection
private void FontCollection()
{
// Create the byte array and get its length
byte[] fontArray = Resources.gill_sans_ultra_bold_condensed;
int dataLength = Resources.gill_sans_ultra_bold_condensed.Length;
// ASSIGN MEMORY AND COPY BYTE[] ON THAT MEMORY ADDRESS
IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
Marshal.Copy(fontArray, 0, ptrData, dataLength);
uint cFonts = 0;
AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);
PrivateFontCollection pfc = new PrivateFontCollection();
//PASS THE FONT TO THE PRIVATEFONTCOLLECTION OBJECT
pfc.AddMemoryFont(ptrData, dataLength);
//FREE THE "UNSAFE" MEMORY
Marshal.FreeCoTaskMem(ptrData);
ff = pfc.Families[0];
font = new Font(ff, 15f, FontStyle.Bold);
fontButtonRegular = new Font(ff, 25f, FontStyle.Bold);
fontButtonSelected = new Font(ff, 30f, FontStyle.Bold);
fontRankings = new Font(ff, 25f, FontStyle.Bold);
MyButton._normalFont = fontButtonRegular;
MyButton._hoverFont = fontButtonSelected;
}
示例10: Initialize
void Initialize()
{
if (privateFontCollection == null)
privateFontCollection = new PrivateFontCollection();
if (privateFonts == null)
privateFonts = new List<XPrivateFont>();
}
示例11: LoadFont
internal static void LoadFont()
{
Fonts = new PrivateFontCollection();
// specify embedded resource name
Stream fontStream = new MemoryStream(Properties.Resources.futura_extrabold);
// create an unsafe memory block for the font data
System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);
// create a buffer to read in to
byte[] fontdata = new byte[fontStream.Length];
//byte[] fontdata = InstagramScreenSaver.Properties.Resources.futura_extrabold;
// read the font data from the resource
fontStream.Read(fontdata, 0, (int)fontStream.Length);
// copy the bytes to the unsafe memory block
Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);
// pass the font to the font collection
Fonts.AddMemoryFont(data, (int)fontStream.Length);
// close the resource stream
fontStream.Close();
// free up the unsafe memory
Marshal.FreeCoTaskMem(data);
}
示例12: LoadCustomFont
private void LoadCustomFont()
{
m_privateFontCollection = new PrivateFontCollection();
m_privateFontCollection.AddFontFile(Directory.GetCurrentDirectory() + "\\content\\Capture_it.ttf");
m_labelFont = new Font(m_privateFontCollection.Families[0], 10.0f, FontStyle.Regular);
}
示例13: ChatPreview
static unsafe ChatPreview()
{
Fonts = new PrivateFontCollection();
fixed( byte* fontPointer = Resources.MinecraftFont ) {
Fonts.AddMemoryFont( (IntPtr)fontPointer, Resources.MinecraftFont.Length );
}
MinecraftFont = new Font( Fonts.Families[0], 12, FontStyle.Regular );
ColorPairs = new[]{
new ColorPair(0,0,0,0,0,0),
new ColorPair(0,0,191,0,0,47),
new ColorPair(0,191,0,0,47,0),
new ColorPair(0,191,191,0,47,47),
new ColorPair(191,0,0,47,0,0),
new ColorPair(191,0,191,47,0,47),
new ColorPair(191,191,0,47,47,0),
new ColorPair(191,191,191,47,47,47),
new ColorPair(64,64,64,16,16,16),
new ColorPair(64,64,255,16,16,63),
new ColorPair(64,255,64,16,63,16),
new ColorPair(64,255,255,16,63,63),
new ColorPair(255,64,64,63,16,16),
new ColorPair(255,64,255,63,16,63),
new ColorPair(255,255,64,63,63,16),
new ColorPair(255,255,255,63,63,63)
};
}
示例14: Form1_Paint
// Draw Faked Beveled effect
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height);
// Text context to store string and font info to be sent as parameter to Canvas methods
TextContext context = new TextContext();
// Load a font from its file into private collection,
// instead of from system font collection
//=============================================================
PrivateFontCollection fontcollection = new PrivateFontCollection();
string szFontFile = "..\\..\\..\\CommonFonts\\Segoe Print.TTF";
fontcollection.AddFontFile(szFontFile);
if (fontcollection.Families.Count() > 0)
context.fontFamily = fontcollection.Families[0];
context.fontStyle = FontStyle.Regular;
context.nfontSize = 38;
context.pszText = "Love Like Magic";
context.ptDraw = new Point(0, 0);
// Draw the main outline
//==========================================================
ITextStrategy mainOutline = Canvas.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 4);
Canvas.DrawTextImage(mainOutline, canvas, new Point(4, 4), context);
// Draw the small bright outline shifted (-2, -2)
//==========================================================
ITextStrategy mainBright = Canvas.TextOutline(Color.FromArgb(252, 173, 250), Color.FromArgb(252, 173, 250), 2);
Canvas.DrawTextImage(mainBright, canvas, new Point(2, 2), context);
// Draw the small dark outline shifted (+2, +2)
//==========================================================
ITextStrategy mainDark = Canvas.TextOutline(Color.FromArgb(126, 5, 123), Color.FromArgb(126, 5, 123), 2);
Canvas.DrawTextImage(mainDark, canvas, new Point(6, 6), context);
// Draw the smallest outline (color same as main outline)
//==========================================================
ITextStrategy mainInner = Canvas.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 2);
Canvas.DrawTextImage(mainInner, canvas, new Point(4, 4), context);
// Finally blit the rendered canvas onto the window
e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);
// Release all the resources
//============================
canvas.Dispose();
mainOutline.Dispose();
mainBright.Dispose();
mainDark.Dispose();
mainInner.Dispose();
}
示例15: TollPrinter
public TollPrinter()
: base()
{
if (pfc == null) {
pfc = new PrivateFontCollection();
AddPrivateFont(pfc, "LabelPrintingSystem_Manifest.code128.ttf");
}
}