Exemplo n.º 1
0
        public TextBlockRenderer(SpriteRenderer sprite, String fontName, FontWeight fontWeight,
                                 FontStyle fontStyle, FontStretch fontStretch, float fontSize)
        {
            AssertDevice();
            IncRefCount();
            Sprite   = sprite;
            FontSize = fontSize;

            Monitor.Enter(sprite.Device);
            try {
                _rtp = new RenderTargetProperties {
                    HorizontalDpi       = 96,
                    VerticalDpi         = 96,
                    Type                = RenderTargetType.Default,
                    PixelFormat         = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                    MinimumFeatureLevel = FeatureLevel.Direct3D10
                };

                Font = ((Factory)WriteFactory).CreateTextFormat(fontName, fontWeight, fontStyle, fontStretch, fontSize,
                                                                CultureInfo.CurrentCulture.Name);
            } finally {
                Monitor.Exit(sprite.Device);
            }

            CreateCharTable(0);
        }
Exemplo n.º 2
0
        public bool RegisterFont(string name, float fontSize, string fontFace = "Arial", FontWeight fontWeight = FontWeight.Normal, FontStyle fontStyle = FontStyle.Normal, FontStretch fontStretch = FontStretch.Normal) {
            if (_fonts.ContainsKey(name)) {
                Console.WriteLine("Duplicate font name: " + name);
                return false;
            }
            try {
                _fonts[name] = new TextBlockRenderer(_sprite, fontFace, fontWeight, fontStyle, fontStretch, fontSize);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return false;
            }

            return true;
        }
Exemplo n.º 3
0
        public TextBlockRenderer(SpriteRenderer sprite, [CanBeNull] IFontCollectionProvider collection, string fontName, FontWeight fontWeight,
                                 FontStyle fontStyle, FontStretch fontStretch, float fontSize, int kerningAdjustment = 0)
        {
            AssertDevice();
            IncRefCount();
            Sprite            = sprite;
            FontSize          = fontSize;
            KerningAdjustment = kerningAdjustment;

            Monitor.Enter(sprite.Device);
            try {
                _rtp = new RenderTargetProperties {
                    HorizontalDpi       = 96,
                    VerticalDpi         = 96,
                    Type                = RenderTargetType.Default,
                    PixelFormat         = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                    MinimumFeatureLevel = FeatureLevel.Direct3D10
                };

                if (collection != null)
                {
                    var c = collection.GetCollection(WriteFactory);
                    if (c.FindFamilyName(fontName) == -1)
                    {
                        fontName = c[0].FamilyNames.get_String(0);
                    }
                    Font = WriteFactory.CreateTextFormat(fontName, c, fontWeight, fontStyle, fontStretch, fontSize,
                                                         CultureInfo.CurrentCulture.Name);
                }
                else
                {
                    Font = WriteFactory.CreateTextFormat(fontName, fontWeight, fontStyle, fontStretch, fontSize, CultureInfo.CurrentCulture.Name);
                }
            } finally {
                Monitor.Exit(sprite.Device);
            }

            CreateCharTable(0);
        }
Exemplo n.º 4
0
        public TextBlockRenderer(SpriteRenderer sprite, String fontName, SlimDX.DirectWrite.FontWeight fontWeight, SlimDX.DirectWrite.FontStyle fontStyle, FontStretch fontStretch, float fontSize)
        {
            Sprite      = sprite;
            FontSize    = fontSize;
            D3DDevice11 = ModelEx.DeviceManager.Instance.device;
            System.Threading.Monitor.Enter(D3DDevice11);
            rtp = new RenderTargetProperties()
            {
                HorizontalDpi       = 96,
                VerticalDpi         = 96,
                Type                = RenderTargetType.Default,
                PixelFormat         = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                MinimumFeatureLevel = FeatureLevel.Direct3D10
            };

            Font = ModelEx.FontManager.Instance.WriteFactory.CreateTextFormat(fontName, fontWeight, fontStyle, fontStretch, fontSize, CultureInfo.CurrentCulture.Name);
            System.Threading.Monitor.Exit(D3DDevice11);
            CreateCharTable(0);
        }
Exemplo n.º 5
0
 public D2DSpriteTextformat CreateTextformat(string fontFamiry, int size = 15, FontWeight weight                 = FontWeight.Normal,
                                             FontStyle style             = FontStyle.Normal, FontStretch stretch = FontStretch.Normal, string locale = "ja-jp")
 {
     return(new D2DSpriteTextformat(this, fontFamiry, size, weight, style, stretch, locale));
 }
Exemplo n.º 6
0
        public bool RegisterFont(string name, float fontSize, string fontFace = "Arial", FontWeight fontWeight = FontWeight.Normal, FontStyle fontStyle = FontStyle.Normal, FontStretch fontStretch = FontStretch.Normal)
        {
            if (_fonts.ContainsKey(name))
            {
                Console.WriteLine("Duplicate font name: " + name);
                return(false);
            }
            try {
                _fonts[name] = new TextBlockRenderer(_sprite, fontFace, fontWeight, fontStyle, fontStretch, fontSize);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
 public TextBlockRenderer(SpriteRenderer sprite, string fontName, FontWeight fontWeight,
                          FontStyle fontStyle, FontStretch fontStretch, float fontSize, int kerningAdjustment = 0)
     : this(sprite, null, fontName, fontWeight, fontStyle, fontStretch, fontSize, kerningAdjustment)
 {
 }