Split Font-File
This commit is contained in:
1 parent
6634e4081d
commit
2f3f121f88
16 files changed
+343
-328
No files matched your search
@@ -22,6 +22,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using Vocaluxe.Screens;
|
using Vocaluxe.Screens;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
using VocaluxeLib.PartyModes;
|
using VocaluxeLib.PartyModes;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
using VocaluxeLib.Menu.SongMenu;
|
using VocaluxeLib.Menu.SongMenu;
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace Vocaluxe.Base
|
namespace Vocaluxe.Base
|
||||||
|
|||||||
@@ -0,0 +1,193 @@
|
|||||||
|
#region license
|
||||||
|
// /*
|
||||||
|
// This file is part of Vocaluxe.
|
||||||
|
//
|
||||||
|
// Vocaluxe is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Vocaluxe is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// */
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Text;
|
||||||
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
|
namespace Vocaluxe.Base.Font
|
||||||
|
{
|
||||||
|
class CFont : IDisposable
|
||||||
|
{
|
||||||
|
private readonly Dictionary<char, CGlyph> _Glyphs;
|
||||||
|
private PrivateFontCollection _Fonts;
|
||||||
|
private FontFamily _Family;
|
||||||
|
private readonly float _Sizeh;
|
||||||
|
|
||||||
|
public readonly string FilePath;
|
||||||
|
|
||||||
|
public CFont(string file)
|
||||||
|
{
|
||||||
|
FilePath = file;
|
||||||
|
|
||||||
|
_Glyphs = new Dictionary<char, CGlyph>();
|
||||||
|
|
||||||
|
switch (CConfig.TextureQuality)
|
||||||
|
{
|
||||||
|
case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST:
|
||||||
|
_Sizeh = 25f;
|
||||||
|
break;
|
||||||
|
case ETextureQuality.TR_CONFIG_TEXTURE_LOW:
|
||||||
|
_Sizeh = 50f;
|
||||||
|
break;
|
||||||
|
case ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM:
|
||||||
|
_Sizeh = 100f;
|
||||||
|
break;
|
||||||
|
case ETextureQuality.TR_CONFIG_TEXTURE_HIGH:
|
||||||
|
_Sizeh = 200f;
|
||||||
|
break;
|
||||||
|
case ETextureQuality.TR_CONFIG_TEXTURE_HIGHEST:
|
||||||
|
_Sizeh = 400f;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_Sizeh = 100f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Drawing.Font GetFont()
|
||||||
|
{
|
||||||
|
if (_Fonts == null)
|
||||||
|
{
|
||||||
|
_Fonts = new PrivateFontCollection();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_Fonts.AddFontFile(FilePath);
|
||||||
|
_Family = _Fonts.Families[0];
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
CLog.LogError("Error opening font file " + FilePath + ": " + e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new System.Drawing.Font(_Family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color)
|
||||||
|
{
|
||||||
|
STexture texture;
|
||||||
|
SRectF rect;
|
||||||
|
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
|
||||||
|
CDraw.DrawTexture(texture, rect, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color, float begin, float end)
|
||||||
|
{
|
||||||
|
STexture texture;
|
||||||
|
SRectF rect;
|
||||||
|
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
|
||||||
|
CDraw.DrawTexture(texture, rect, color, begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight)
|
||||||
|
{
|
||||||
|
STexture texture;
|
||||||
|
SRectF rect;
|
||||||
|
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
|
||||||
|
CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _GetGlyphTextureAndRect(char chr, float x, float y, float z, float h, out STexture texture, out SRectF rect)
|
||||||
|
{
|
||||||
|
AddGlyph(chr);
|
||||||
|
|
||||||
|
CFonts.Height = h;
|
||||||
|
CGlyph glyph = _Glyphs[chr];
|
||||||
|
texture = glyph.Texture;
|
||||||
|
float factor = h / texture.Height;
|
||||||
|
float width = texture.Width * factor;
|
||||||
|
float d = glyph.Sizeh / 5f * factor;
|
||||||
|
rect = new SRectF(x - d, y, width, h, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetWidth(char chr)
|
||||||
|
{
|
||||||
|
AddGlyph(chr);
|
||||||
|
|
||||||
|
CGlyph glyph = _Glyphs[chr];
|
||||||
|
float factor = CFonts.Height / glyph.Texture.Height;
|
||||||
|
return glyph.Width * factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetHeight(char chr)
|
||||||
|
{
|
||||||
|
return CFonts.Height;
|
||||||
|
/*WTF???
|
||||||
|
AddGlyph(chr);
|
||||||
|
|
||||||
|
CGlyph glyph = _Glyphs[chr];
|
||||||
|
float factor = CFonts.Height / glyph.Texture.height;
|
||||||
|
return glyph.Texture.height * factor;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddGlyph(char chr)
|
||||||
|
{
|
||||||
|
if (_Glyphs.ContainsKey(chr))
|
||||||
|
return;
|
||||||
|
|
||||||
|
float h = CFonts.Height;
|
||||||
|
_Glyphs.Add(chr, new CGlyph(chr, _Sizeh));
|
||||||
|
CFonts.Height = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnloadAllGlyphs()
|
||||||
|
{
|
||||||
|
foreach (CGlyph glyph in _Glyphs.Values)
|
||||||
|
glyph.UnloadTexture();
|
||||||
|
_Glyphs.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_Fonts != null)
|
||||||
|
{
|
||||||
|
_Fonts.Dispose();
|
||||||
|
_Fonts = null;
|
||||||
|
UnloadAllGlyphs();
|
||||||
|
}
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SFont
|
||||||
|
{
|
||||||
|
public string Name;
|
||||||
|
|
||||||
|
public bool IsThemeFont;
|
||||||
|
public int PartyModeID;
|
||||||
|
public string ThemeName;
|
||||||
|
|
||||||
|
public string Folder;
|
||||||
|
public string FileNormal;
|
||||||
|
public string FileItalic;
|
||||||
|
public string FileBold;
|
||||||
|
public string FileBoldItalic;
|
||||||
|
|
||||||
|
public float Outline; //0..1, 0=not outline 1=100% outline
|
||||||
|
public SColorF OutlineColor;
|
||||||
|
|
||||||
|
public CFont Normal;
|
||||||
|
public CFont Italic;
|
||||||
|
public CFont Bold;
|
||||||
|
public CFont BoldItalic;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,321 +1,13 @@
|
|||||||
#region license
|
|
||||||
// /*
|
|
||||||
// This file is part of Vocaluxe.
|
|
||||||
//
|
|
||||||
// Vocaluxe is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Vocaluxe is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
// */
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using System.Drawing.Text;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace Vocaluxe.Base
|
namespace Vocaluxe.Base.Font
|
||||||
{
|
{
|
||||||
class CGlyph
|
|
||||||
{
|
|
||||||
private readonly float _Sizeh = 50f;
|
|
||||||
public float Sizeh
|
|
||||||
{
|
|
||||||
get { return _Sizeh; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public STexture Texture;
|
|
||||||
public readonly int Width;
|
|
||||||
|
|
||||||
public CGlyph(char chr, float maxHigh)
|
|
||||||
{
|
|
||||||
_Sizeh = maxHigh;
|
|
||||||
|
|
||||||
float outline = CFonts.Outline;
|
|
||||||
const TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix;
|
|
||||||
|
|
||||||
float factor = _GetFactor(chr, flags);
|
|
||||||
CFonts.Height = Sizeh * factor;
|
|
||||||
Font fo;
|
|
||||||
Size sizeB;
|
|
||||||
SizeF size;
|
|
||||||
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
|
||||||
{
|
|
||||||
fo = CFonts.GetFont();
|
|
||||||
sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
|
|
||||||
|
|
||||||
size = g.MeasureString(chr.ToString(), fo);
|
|
||||||
}
|
|
||||||
|
|
||||||
using (Bitmap bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height))
|
|
||||||
{
|
|
||||||
Graphics g = Graphics.FromImage(bmp);
|
|
||||||
g.Clear(Color.Transparent);
|
|
||||||
|
|
||||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
||||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
||||||
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
|
||||||
CFonts.Height = Sizeh;
|
|
||||||
fo = CFonts.GetFont();
|
|
||||||
|
|
||||||
PointF point = new PointF(
|
|
||||||
outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + Sizeh / 5f,
|
|
||||||
(sizeB.Height - size.Height - (size.Height + Sizeh / 4f) * (1f - factor)) / 2f);
|
|
||||||
|
|
||||||
using (GraphicsPath path = new GraphicsPath())
|
|
||||||
{
|
|
||||||
path.AddString(
|
|
||||||
chr.ToString(),
|
|
||||||
fo.FontFamily,
|
|
||||||
(int)fo.Style,
|
|
||||||
Sizeh,
|
|
||||||
point,
|
|
||||||
new StringFormat());
|
|
||||||
|
|
||||||
using (Pen pen = new Pen(
|
|
||||||
Color.FromArgb(
|
|
||||||
(int)CFonts.OutlineColor.A * 255,
|
|
||||||
(int)CFonts.OutlineColor.R * 255,
|
|
||||||
(int)CFonts.OutlineColor.G * 255,
|
|
||||||
(int)CFonts.OutlineColor.B * 255),
|
|
||||||
Sizeh * outline))
|
|
||||||
{
|
|
||||||
pen.LineJoin = LineJoin.Round;
|
|
||||||
g.DrawPath(pen, path);
|
|
||||||
g.FillPath(Brushes.White, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
g.DrawString(
|
|
||||||
chr.ToString(),
|
|
||||||
fo,
|
|
||||||
Brushes.White,
|
|
||||||
point);
|
|
||||||
* */
|
|
||||||
Texture = CDraw.AddTexture(bmp);
|
|
||||||
//bmp.Save("test.png", ImageFormat.Png);
|
|
||||||
Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width);
|
|
||||||
g.Dispose();
|
|
||||||
}
|
|
||||||
fo.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnloadTexture()
|
|
||||||
{
|
|
||||||
CDraw.RemoveTexture(ref Texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
private float _GetFactor(char chr, TextFormatFlags flags)
|
|
||||||
{
|
|
||||||
if (CFonts.Style == EStyle.Normal)
|
|
||||||
return 1f;
|
|
||||||
|
|
||||||
EStyle style = CFonts.Style;
|
|
||||||
|
|
||||||
CFonts.Style = EStyle.Normal;
|
|
||||||
CFonts.Height = Sizeh;
|
|
||||||
float hStyle, hNormal;
|
|
||||||
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
|
||||||
{
|
|
||||||
Font fo = CFonts.GetFont();
|
|
||||||
Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
|
|
||||||
//SizeF size = g.MeasureString(chr.ToString(), fo);
|
|
||||||
hNormal = sizeB.Height;
|
|
||||||
}
|
|
||||||
CFonts.Style = style;
|
|
||||||
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
|
||||||
{
|
|
||||||
Font fo = CFonts.GetFont();
|
|
||||||
Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
|
|
||||||
//size = g.MeasureString(chr.ToString(), fo);
|
|
||||||
hStyle = sizeB.Height;
|
|
||||||
}
|
|
||||||
return hNormal / hStyle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CFont : IDisposable
|
|
||||||
{
|
|
||||||
private readonly Dictionary<char, CGlyph> _Glyphs;
|
|
||||||
private PrivateFontCollection _Fonts;
|
|
||||||
private FontFamily _Family;
|
|
||||||
private readonly float _Sizeh;
|
|
||||||
|
|
||||||
public readonly string FilePath;
|
|
||||||
|
|
||||||
public CFont(string file)
|
|
||||||
{
|
|
||||||
FilePath = file;
|
|
||||||
|
|
||||||
_Glyphs = new Dictionary<char, CGlyph>();
|
|
||||||
|
|
||||||
switch (CConfig.TextureQuality)
|
|
||||||
{
|
|
||||||
case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST:
|
|
||||||
_Sizeh = 25f;
|
|
||||||
break;
|
|
||||||
case ETextureQuality.TR_CONFIG_TEXTURE_LOW:
|
|
||||||
_Sizeh = 50f;
|
|
||||||
break;
|
|
||||||
case ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM:
|
|
||||||
_Sizeh = 100f;
|
|
||||||
break;
|
|
||||||
case ETextureQuality.TR_CONFIG_TEXTURE_HIGH:
|
|
||||||
_Sizeh = 200f;
|
|
||||||
break;
|
|
||||||
case ETextureQuality.TR_CONFIG_TEXTURE_HIGHEST:
|
|
||||||
_Sizeh = 400f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
_Sizeh = 100f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Font GetFont()
|
|
||||||
{
|
|
||||||
if (_Fonts == null)
|
|
||||||
{
|
|
||||||
_Fonts = new PrivateFontCollection();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_Fonts.AddFontFile(FilePath);
|
|
||||||
_Family = _Fonts.Families[0];
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
CLog.LogError("Error opening font file " + FilePath + ": " + e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Font(_Family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color)
|
|
||||||
{
|
|
||||||
STexture texture;
|
|
||||||
SRectF rect;
|
|
||||||
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
|
|
||||||
CDraw.DrawTexture(texture, rect, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color, float begin, float end)
|
|
||||||
{
|
|
||||||
STexture texture;
|
|
||||||
SRectF rect;
|
|
||||||
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
|
|
||||||
CDraw.DrawTexture(texture, rect, color, begin, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight)
|
|
||||||
{
|
|
||||||
STexture texture;
|
|
||||||
SRectF rect;
|
|
||||||
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
|
|
||||||
CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void _GetGlyphTextureAndRect(char chr, float x, float y, float z, float h, out STexture texture, out SRectF rect)
|
|
||||||
{
|
|
||||||
AddGlyph(chr);
|
|
||||||
|
|
||||||
CFonts.Height = h;
|
|
||||||
CGlyph glyph = _Glyphs[chr];
|
|
||||||
texture = glyph.Texture;
|
|
||||||
float factor = h / texture.Height;
|
|
||||||
float width = texture.Width * factor;
|
|
||||||
float d = glyph.Sizeh / 5f * factor;
|
|
||||||
rect = new SRectF(x - d, y, width, h, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float GetWidth(char chr)
|
|
||||||
{
|
|
||||||
AddGlyph(chr);
|
|
||||||
|
|
||||||
CGlyph glyph = _Glyphs[chr];
|
|
||||||
float factor = CFonts.Height / glyph.Texture.Height;
|
|
||||||
return glyph.Width * factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float GetHeight(char chr)
|
|
||||||
{
|
|
||||||
return CFonts.Height;
|
|
||||||
/*WTF???
|
|
||||||
AddGlyph(chr);
|
|
||||||
|
|
||||||
CGlyph glyph = _Glyphs[chr];
|
|
||||||
float factor = CFonts.Height / glyph.Texture.height;
|
|
||||||
return glyph.Texture.height * factor;*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddGlyph(char chr)
|
|
||||||
{
|
|
||||||
if (_Glyphs.ContainsKey(chr))
|
|
||||||
return;
|
|
||||||
|
|
||||||
float h = CFonts.Height;
|
|
||||||
_Glyphs.Add(chr, new CGlyph(chr, _Sizeh));
|
|
||||||
CFonts.Height = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnloadAllGlyphs()
|
|
||||||
{
|
|
||||||
foreach (CGlyph glyph in _Glyphs.Values)
|
|
||||||
glyph.UnloadTexture();
|
|
||||||
_Glyphs.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (_Fonts != null)
|
|
||||||
{
|
|
||||||
_Fonts.Dispose();
|
|
||||||
_Fonts = null;
|
|
||||||
UnloadAllGlyphs();
|
|
||||||
}
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SFont
|
|
||||||
{
|
|
||||||
public string Name;
|
|
||||||
|
|
||||||
public bool IsThemeFont;
|
|
||||||
public int PartyModeID;
|
|
||||||
public string ThemeName;
|
|
||||||
|
|
||||||
public string Folder;
|
|
||||||
public string FileNormal;
|
|
||||||
public string FileItalic;
|
|
||||||
public string FileBold;
|
|
||||||
public string FileBoldItalic;
|
|
||||||
|
|
||||||
public float Outline; //0..1, 0=not outline 1=100% outline
|
|
||||||
public SColorF OutlineColor;
|
|
||||||
|
|
||||||
public CFont Normal;
|
|
||||||
public CFont Italic;
|
|
||||||
public CFont Bold;
|
|
||||||
public CFont BoldItalic;
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CFonts
|
static class CFonts
|
||||||
{
|
{
|
||||||
private static readonly XmlWriterSettings _Settings = new XmlWriterSettings();
|
private static readonly XmlWriterSettings _Settings = new XmlWriterSettings();
|
||||||
@@ -372,7 +64,7 @@ namespace Vocaluxe.Base
|
|||||||
_LoadFontList();
|
_LoadFontList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Font GetFont()
|
public static System.Drawing.Font GetFont()
|
||||||
{
|
{
|
||||||
return _GetCurrentFont().GetFont();
|
return _GetCurrentFont().GetFont();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
|
namespace Vocaluxe.Base.Font
|
||||||
|
{
|
||||||
|
class CGlyph
|
||||||
|
{
|
||||||
|
private readonly float _Sizeh = 50f;
|
||||||
|
public float Sizeh
|
||||||
|
{
|
||||||
|
get { return _Sizeh; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public STexture Texture;
|
||||||
|
public readonly int Width;
|
||||||
|
|
||||||
|
public CGlyph(char chr, float maxHigh)
|
||||||
|
{
|
||||||
|
_Sizeh = maxHigh;
|
||||||
|
|
||||||
|
float outline = CFonts.Outline;
|
||||||
|
const TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix;
|
||||||
|
|
||||||
|
float factor = _GetFactor(chr, flags);
|
||||||
|
CFonts.Height = Sizeh * factor;
|
||||||
|
System.Drawing.Font fo;
|
||||||
|
Size sizeB;
|
||||||
|
SizeF size;
|
||||||
|
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
||||||
|
{
|
||||||
|
fo = CFonts.GetFont();
|
||||||
|
sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
|
||||||
|
|
||||||
|
size = g.MeasureString(chr.ToString(), fo);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (Bitmap bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height))
|
||||||
|
{
|
||||||
|
Graphics g = Graphics.FromImage(bmp);
|
||||||
|
g.Clear(Color.Transparent);
|
||||||
|
|
||||||
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||||
|
CFonts.Height = Sizeh;
|
||||||
|
fo = CFonts.GetFont();
|
||||||
|
|
||||||
|
PointF point = new PointF(
|
||||||
|
outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + Sizeh / 5f,
|
||||||
|
(sizeB.Height - size.Height - (size.Height + Sizeh / 4f) * (1f - factor)) / 2f);
|
||||||
|
|
||||||
|
using (GraphicsPath path = new GraphicsPath())
|
||||||
|
{
|
||||||
|
path.AddString(
|
||||||
|
chr.ToString(),
|
||||||
|
fo.FontFamily,
|
||||||
|
(int)fo.Style,
|
||||||
|
Sizeh,
|
||||||
|
point,
|
||||||
|
new StringFormat());
|
||||||
|
|
||||||
|
using (Pen pen = new Pen(
|
||||||
|
Color.FromArgb(
|
||||||
|
(int)CFonts.OutlineColor.A * 255,
|
||||||
|
(int)CFonts.OutlineColor.R * 255,
|
||||||
|
(int)CFonts.OutlineColor.G * 255,
|
||||||
|
(int)CFonts.OutlineColor.B * 255),
|
||||||
|
Sizeh * outline))
|
||||||
|
{
|
||||||
|
pen.LineJoin = LineJoin.Round;
|
||||||
|
g.DrawPath(pen, path);
|
||||||
|
g.FillPath(Brushes.White, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
g.DrawString(
|
||||||
|
chr.ToString(),
|
||||||
|
fo,
|
||||||
|
Brushes.White,
|
||||||
|
point);
|
||||||
|
* */
|
||||||
|
Texture = CDraw.AddTexture(bmp);
|
||||||
|
//bmp.Save("test.png", ImageFormat.Png);
|
||||||
|
Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width);
|
||||||
|
g.Dispose();
|
||||||
|
}
|
||||||
|
fo.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnloadTexture()
|
||||||
|
{
|
||||||
|
CDraw.RemoveTexture(ref Texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float _GetFactor(char chr, TextFormatFlags flags)
|
||||||
|
{
|
||||||
|
if (CFonts.Style == EStyle.Normal)
|
||||||
|
return 1f;
|
||||||
|
|
||||||
|
EStyle style = CFonts.Style;
|
||||||
|
|
||||||
|
CFonts.Style = EStyle.Normal;
|
||||||
|
CFonts.Height = Sizeh;
|
||||||
|
float hStyle, hNormal;
|
||||||
|
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
||||||
|
{
|
||||||
|
System.Drawing.Font fo = CFonts.GetFont();
|
||||||
|
Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
|
||||||
|
//SizeF size = g.MeasureString(chr.ToString(), fo);
|
||||||
|
hNormal = sizeB.Height;
|
||||||
|
}
|
||||||
|
CFonts.Style = style;
|
||||||
|
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
||||||
|
{
|
||||||
|
System.Drawing.Font fo = CFonts.GetFont();
|
||||||
|
Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
|
||||||
|
//size = g.MeasureString(chr.ToString(), fo);
|
||||||
|
hStyle = sizeB.Height;
|
||||||
|
}
|
||||||
|
return hNormal / hStyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using SlimDX.Windows;
|
using SlimDX.Windows;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace Vocaluxe.Lib.Draw
|
namespace Vocaluxe.Lib.Draw
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace Vocaluxe.Lib.Draw
|
namespace Vocaluxe.Lib.Draw
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ using System.IO;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace Vocaluxe.Lib.Draw
|
namespace Vocaluxe.Lib.Draw
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ using System.Reflection;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
|
|
||||||
namespace Vocaluxe
|
namespace Vocaluxe
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace Vocaluxe.Screens
|
namespace Vocaluxe.Screens
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace Vocaluxe.Screens
|
namespace Vocaluxe.Screens
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using Vocaluxe.Base.Font;
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
using VocaluxeLib.Menu.SingNotes;
|
using VocaluxeLib.Menu.SingNotes;
|
||||||
using VocaluxeLib.Menu.SongMenu;
|
using VocaluxeLib.Menu.SongMenu;
|
||||||
@@ -522,8 +523,8 @@ namespace Vocaluxe.Screens
|
|||||||
|
|
||||||
if (_Pause)
|
if (_Pause)
|
||||||
{
|
{
|
||||||
_Statics[_StaticPauseBG].ForceDraw();
|
_Statics[_StaticPauseBG].Draw(true);
|
||||||
_Texts[_TextPause].ForceDraw();
|
_Texts[_TextPause].Draw(true);
|
||||||
|
|
||||||
foreach (CButton button in _Buttons)
|
foreach (CButton button in _Buttons)
|
||||||
button.Draw();
|
button.Draw();
|
||||||
|
|||||||
@@ -176,7 +176,7 @@
|
|||||||
<Compile Include="Base\CCover.cs" />
|
<Compile Include="Base\CCover.cs" />
|
||||||
<Compile Include="Base\CDataBase.cs" />
|
<Compile Include="Base\CDataBase.cs" />
|
||||||
<Compile Include="Base\CDraw.cs" />
|
<Compile Include="Base\CDraw.cs" />
|
||||||
<Compile Include="Base\CFont.cs" />
|
<Compile Include="Base\Font\CFont.cs" />
|
||||||
<Compile Include="Base\CGame.cs" />
|
<Compile Include="Base\CGame.cs" />
|
||||||
<Compile Include="Base\CInput.cs" />
|
<Compile Include="Base\CInput.cs" />
|
||||||
<Compile Include="Base\CLanguage.cs" />
|
<Compile Include="Base\CLanguage.cs" />
|
||||||
@@ -195,6 +195,8 @@
|
|||||||
<Compile Include="Base\CTheme.cs" />
|
<Compile Include="Base\CTheme.cs" />
|
||||||
<Compile Include="Base\CVideo.cs" />
|
<Compile Include="Base\CVideo.cs" />
|
||||||
<Compile Include="Base\CWebcam.cs" />
|
<Compile Include="Base\CWebcam.cs" />
|
||||||
|
<Compile Include="Base\Font\CFonts.cs" />
|
||||||
|
<Compile Include="Base\Font\CGlyph.cs" />
|
||||||
<Compile Include="CSplashScreen.cs">
|
<Compile Include="CSplashScreen.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -221,27 +221,22 @@ namespace VocaluxeLib.Menu
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw(bool forceDraw = false)
|
||||||
{
|
{
|
||||||
Draw(1f, Rect.Z, Aspect, false);
|
Draw(1f, Rect.Z, Aspect, forceDraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(EAspect aspect)
|
public void Draw(EAspect aspect)
|
||||||
{
|
{
|
||||||
Draw(1f, Rect.Z, aspect, false);
|
Draw(1f, Rect.Z, aspect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(float scale, EAspect aspect)
|
public void Draw(float scale, EAspect aspect)
|
||||||
{
|
{
|
||||||
Draw(scale, Rect.Z, aspect, false);
|
Draw(scale, Rect.Z, aspect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ForceDraw()
|
public void Draw(float scale, float z, EAspect aspect, bool forceDraw = false)
|
||||||
{
|
|
||||||
Draw(1f, Rect.Z, Aspect, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(float scale, float z, EAspect aspect, bool forceDraw)
|
|
||||||
{
|
{
|
||||||
STexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID);
|
STexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID);
|
||||||
|
|
||||||
|
|||||||
@@ -601,11 +601,6 @@ namespace VocaluxeLib.Menu
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ForceDraw()
|
|
||||||
{
|
|
||||||
Draw(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(bool forceDraw = false)
|
public void Draw(bool forceDraw = false)
|
||||||
{
|
{
|
||||||
if (!forceDraw && !Visible && CBase.Settings.GetGameState() != EGameState.EditTheme)
|
if (!forceDraw && !Visible && CBase.Settings.GetGameState() != EGameState.EditTheme)
|
||||||
|
|||||||
Reference in new issue
Block a user