/// <summary> /// Init this instance to /// </summary> public static void Init() { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); FontLoader.LoadFonts (assemblies, (fontName, s) => { fontName = fontName.ToLowerInvariant(); var copyStream = new MemoryStream(); s.CopyTo(copyStream); Typefaces[fontName] = new FontSource(copyStream); }); }
protected override void SetupMainPage(MainPage mainPage) { FontSource uiFontSource = new FontSource(Application.GetResourceStream( new Uri("/ChicksnVixens;component/Content/NGO_____.TTF", UriKind.Relative)).Stream); FontFamily uiFontFamily = new FontFamily("News Gothic"); ContentManager.SilverlightFontTranslation("UIFont", new SpriteFontTTF(uiFontSource, uiFontFamily, 16)); var game = new ChicksnVixensGame(NamedScreenSizes.Get("web")); mainPage.Children.Add(game); game.Play(); }
protected override void SetupMainPage(MainPage mainPage) { mPage = mainPage; FontSource fontSource = new FontSource(Application.GetResourceStream(new Uri("SoshiLandSilverLight;component/Content/nobile.ttf", UriKind.Relative)).Stream); FontFamily fontFamily = new FontFamily("Nobile"); ContentManager.SilverlightFontTranslation("SpriteFont1", new SpriteFontTTF(fontSource, fontFamily, 14)); ChangeGameState(GameState.InGame); // Start the app by prompting User Name //ChangeGameState(GameState.EnterUserName); }
/// <param name="fontSize">Font size in points.</param> public SpriteFontTTF(FontSource source, FontFamily family, int fontSize) { this.FontFamily = family; this.FontSource = source; this.FontSize = fontSize * pointsToPixels; measuringTextBlock = new TextBlock() { FontSize = FontSize, FontFamily = FontFamily, FontSource = FontSource }; }
public void Init(Ioctls ioctls, Core core, Runtime runtime) { ioctls.maFontGetCount = delegate() { int count = 0; MoSync.Util.RunActionOnMainThreadSync(() => count = System.Windows.Media.Fonts.SystemTypefaces.Count); return count; }; ioctls.maFontGetName = delegate(int _index, int _buffer, int _bufferLen) { if (_index > ioctls.maFontGetCount()) { return MoSync.Constants.RES_FONT_INDEX_OUT_OF_BOUNDS; } else { String fontName = ""; MoSync.Util.RunActionOnMainThreadSync(() => { int count = 0; System.Collections.Generic.IEnumerator<Typeface> en = System.Windows.Media.Fonts.SystemTypefaces.GetEnumerator(); while (count < _index) { en.MoveNext(); count++; } System.Windows.Media.Typeface currentTypeFace = en.Current; System.Windows.Media.GlyphTypeface currentGlyph; currentTypeFace.TryGetGlyphTypeface(out currentGlyph); fontName = currentGlyph.FontFileName; fontName = (fontName.Split('.'))[0]; }); if (fontName.Length > _bufferLen) return MoSync.Constants.RES_FONT_INSUFFICIENT_BUFFER; core.GetDataMemory().WriteStringAtAddress(_buffer, fontName, _bufferLen); return MoSync.Constants.RES_FONT_OK; } }; ioctls.maFontLoadWithName = delegate(int _postScriptName, int _size) { String fontName = core.GetDataMemory().ReadStringAtAddress(_postScriptName); Typeface typeface = null; GlyphTypeface glyphTypeface = null; MoSync.Util.RunActionOnMainThreadSync(() => { int count = Fonts.SystemTypefaces.Count; System.Collections.Generic.IEnumerator<Typeface> en = Fonts.SystemTypefaces.GetEnumerator(); while (count != 0) { typeface = en.Current; if (typeface.TryGetGlyphTypeface(out glyphTypeface)) { if (glyphTypeface.FontFileName.StartsWith(fontName)) { break; } } en.MoveNext(); count--; } }); if (glyphTypeface == null) return -2; mFonts.Add(glyphTypeface); return mFonts.Count - 1; }; ioctls.maFontLoadDefault = delegate(int _type, int _style, int _size) { //RES_FONT_NO_TYPE_STYLE_COMBINATION //RES_FONT_INVALID_SIZE switch (_type) { case MoSync.Constants.FONT_TYPE_MONOSPACE: break; case MoSync.Constants.FONT_TYPE_SERIF: break; case MoSync.Constants.FONT_TYPE_SANS_SERIF: break; default: return MoSync.Constants.RES_FONT_NO_TYPE_STYLE_COMBINATION; } return 0; }; ioctls.maFontSetCurrent = delegate(int _font) { mCurrentFont = mFonts[_font]; mCurrentFontSource = new System.Windows.Documents.FontSource(mCurrentFont); return 0; }; }