Пример #1
0
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            base.Initialize(demoConfiguration);
            Factory2D = new SharpDX.Direct2D1.Factory();
            using (var surface = BackBuffer.QueryInterface<Surface>())
            {
                RenderTarget2D = new RenderTarget(Factory2D, surface,
                                                  new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
Пример #2
0
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            base.Initialize(demoConfiguration);
            Factory2D = new SharpDX.Direct2D1.Factory();
            using (var surface = BackBuffer.QueryInterface <Surface>())
            {
                RenderTarget2D = new RenderTarget(Factory2D, surface,
                                                  new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            Factory2D = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            HwndRenderTargetProperties properties = new HwndRenderTargetProperties();
            properties.Hwnd = DisplayHandle;
            properties.PixelSize = new System.Drawing.Size(demoConfiguration.Width, demoConfiguration.Height);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 1, 1, 1));
        }
Пример #4
0
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D     = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties();

            properties.Hwnd           = renderControl.Handle;
            properties.PixelSize      = new Size2(renderControl.ClientSize.Width, renderControl.ClientSize.Height);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);
            RenderTarget2D.AntialiasMode     = AntialiasMode.PerPrimitive;
            RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.Black);
        }
Пример #5
0
        protected virtual void Initialize2D()
        {
#if DEBUG
            Factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded, DebugLevel.Information);
#else
            Factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded);
#endif
            using (var surface = BackBuffer.QueryInterface <Surface>())
            {
                RenderTarget = new RenderTarget(Factory2D, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            RenderTarget.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            SceneColorBrush = new SolidColorBrush(RenderTarget, Color.White);
        }
        public SharpDxGraphicsManagerWrapper(Panel targetPanel, Action renderAction)
            : base(renderAction)
        {
            var Factory2D     = new SharpDX.Direct2D1.Factory();
            var FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties();

            properties.Hwnd           = targetPanel.Handle;
            properties.PixelSize      = new SharpDX.Size2(targetPanel.Width, targetPanel.Height);
            properties.PresentOptions = PresentOptions.None;

            _renderTarget = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            _renderTarget.AntialiasMode = AntialiasMode.PerPrimitive;

            _wrapper = new DxGraphicsWrapper(_renderTarget, FactoryDWrite, new ImagingFactory());
        }
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            Factory2D     = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            HwndRenderTargetProperties properties = new HwndRenderTargetProperties();

            properties.Hwnd           = DisplayHandle;
            properties.PixelSize      = new SharpDX.Size2(demoConfiguration.Width, demoConfiguration.Height);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;


            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
Пример #8
0
        public static SharpDX.Direct2D1.StrokeStyle ToStrokeStyle(this Pen pen, SharpDX.Direct2D1.Factory factory)
        {
            SharpDX.Direct2D1.StrokeStyleProperties properties = new SharpDX.Direct2D1.StrokeStyleProperties
            {
                DashCap    = _dashCapMap[pen.DashCap],
                DashOffset = pen.DashOffset,
                DashStyle  = _dashStyleMap[pen.DashStyle],
                EndCap     = _lineCapMap[pen.EndCap],
                LineJoin   = _lineJoinMap[pen.LineJoin],
                MiterLimit = pen.MiterLimit,
                StartCap   = _lineCapMap[pen.StartCap],
            };

            if (pen.DashStyle == DashStyle.Custom)
            {
                return(new SharpDX.Direct2D1.StrokeStyle(factory, properties, pen.DashPattern));
            }
            return(new SharpDX.Direct2D1.StrokeStyle(factory, properties));
        }
Пример #9
0
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D     = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties {
                Hwnd = Handle, PixelSize = ClientSize, PresentOptions = PresentOptions.None
            };

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(), properties)
            {
                AntialiasMode     = AntialiasMode.PerPrimitive,
                TextAntialiasMode = TextAntialiasMode.Cleartype
            };

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 0, 0, 0));

            CustomTextRenderer = new CustomTextRenderer(Factory2D, RenderTarget2D);
        }
Пример #10
0
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                _currentFont = GetFont(fontName, fontSize);

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
                CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
            }

            return(_currentFont);
        }
Пример #11
0
        protected void CreateFactory()
        {
            if (factory == null)
            {
                try
                {
                    // Some Windows 7 versions dont have version 1 of the factory.
                    factory = new SharpDX.Direct2D1.Factory1();
                }
                catch
                {
                    factory = new SharpDX.Direct2D1.Factory();
                }

                factoryRefCount = 1;
            }
            else
            {
                factoryRefCount++;
            }
        }
Пример #12
0
        public Direct2DOffscreenGraphics(int imageSizeX, int imageSizeY)
        {
            d3dDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);

            offscreenTexture = new SharpDX.Direct3D11.Texture2D(d3dDevice, new SharpDX.Direct3D11.Texture2DDescription
            {
                BindFlags         = SharpDX.Direct3D11.BindFlags.RenderTarget | SharpDX.Direct3D11.BindFlags.ShaderResource,
                CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = imageSizeX,
                Height            = imageSizeY,
                MipLevels         = 1,
                ArraySize         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = SharpDX.Direct3D11.ResourceUsage.Default
            });

            stagingTexture = new SharpDX.Direct3D11.Texture2D(d3dDevice, new SharpDX.Direct3D11.Texture2DDescription
            {
                BindFlags         = SharpDX.Direct3D11.BindFlags.None,
                CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.Read,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = imageSizeX,
                Height            = imageSizeY,
                MipLevels         = 1,
                ArraySize         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = SharpDX.Direct3D11.ResourceUsage.Staging
            });

            windowScaling = 1.0f; // No scaling for now in videos.
            factory       = new SharpDX.Direct2D1.Factory();
            renderTarget  = new RenderTarget(factory, offscreenTexture.QueryInterface <SharpDX.DXGI.Surface>(), new RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));

            Initialize();
        }
Пример #13
0
        private string CreateFont(string fontName, float fontSize, CCRawList <char> charset)
        {
            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                //if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                //{

                //    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                //    //var contentPath = Path.Combine(appPath, CCContentManager.SharedContentManager.RootDirectory);
                //    //var fontPath = Path.Combine(contentPath, fontName);

                //    //if (File.Exists(fontPath))
                //    //{
                //    //    try
                //    //    {
                //    //        if (privateFontLoader == null)
                //    //        {
                //    //            privateFontLoader = new PrivateFontLoader(FactoryDWrite, fontName);
                //    //            privateFontCollection = new FontCollection(FactoryDWrite, privateFontLoader, privateFontLoader.Key);
                //    //        }

                //    //        _currentFontCollection = privateFontCollection;

                //    //        var family = _currentFontCollection.GetFontFamily(0);
                //    //        // This is generic right now.  We should be able to handle different styles in the future
                //    //        var font = family.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                //    //        _currentFont = font;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //    catch
                //    //    {
                //    //        _currentFont = _defaultFont;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //}

                //    //else
                //    //{
                //    //    _currentFont = _defaultFont;
                //    //    _currentFontSizeEm = fontSize;
                //    //    _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //}
                //}
                //else
                //{
                _currentFont       = GetFont(fontName, fontSize);
                _currentFontSizeEm = fontSize;
                _currentDIP        = ConvertPointSizeToDIP(fontSize);
                //}

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont       = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP        = ConvertPointSizeToDIP(fontSize);
            }

            fontName   = _currentFont.FontFamily.FamilyNames.GetString(0);
            textFormat = new TextFormat(FactoryDWrite, fontName,
                                        _currentFontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, _currentDIP);

            GetKerningInfo(charset);

            return(_currentFont.ToString());
        }
Пример #14
0
        private string CreateFont(string fontName, float fontSize, CCRawList <char> charset)
        {
            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                    //var contentPath = Path.Combine(appPath, CCApplication.SharedApplication.Content.RootDirectory);
                    //var fontPath = Path.Combine(contentPath, fontName);

                    //if (File.Exists(fontPath))
                    //{
                    // try
                    //{
                    //var fontFileReference = new FontCollection(
                    //_loadedFonts.AddFontFile(fontPath);

                    //        //fontFamily = _loadedFonts.Families[_loadedFonts.Families.Length - 1];

                    //        //_currentFont = new Font(fontFamily, fontSize);
                    //    }
                    //    catch
                    //    {
                    //        _currentFont = _defaultFont;
                    //    }
                    //}
                    //else
                    //{
                    _currentFont       = _defaultFont;
                    _currentFontSizeEm = fontSize;
                    _currentDIP        = ConvertPointSizeToDIP(fontSize);
                    //}
                }
                else
                {
                    _currentFont       = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP        = ConvertPointSizeToDIP(fontSize);
                }

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont       = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP        = ConvertPointSizeToDIP(fontSize);
            }
            fontName   = _currentFont.FontFamily.FamilyNames.GetString(0);
            textFormat = new TextFormat(FactoryDWrite, fontName, _currentDIP);

            GetKerningInfo(charset);

            return(_currentFont.ToString());
        }
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;

            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            FontCollection fontCollection;

            if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection))
            {
                var ext = Path.GetExtension(fontName);

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        var fileFontLoader = new FileFontLoader(FactoryDWrite, fontName);
                        var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key);
                        _currentFontCollection = fileFontCollection;
                        fontFamily = _currentFontCollection.GetFontFamily(0);
                        var ffn = fontFamily.FamilyNames;
                        _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);

                        _fontCollectionCache.Add(fontName, fileFontCollection);
                        _currentFontCollection = fileFontCollection;
                    }
                    catch
                    {
                        _currentFont = GetFont(fontName, fontSize);
                        CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
                    }
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                }

            }
            else
            {
                fontFamily = fontCollection.GetFontFamily(0);

                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontCollection = fontCollection;
            }

            return _currentFont;
        }
Пример #16
0
        private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        {

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();
                
                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;

            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                //if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                //{

                //    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                //    //var contentPath = Path.Combine(appPath, CCContentManager.SharedContentManager.RootDirectory);
                //    //var fontPath = Path.Combine(contentPath, fontName);

                //    //if (File.Exists(fontPath))
                //    //{
                //    //    try
                //    //    {
                //    //        if (privateFontLoader == null)
                //    //        {
                //    //            privateFontLoader = new PrivateFontLoader(FactoryDWrite, fontName);
                //    //            privateFontCollection = new FontCollection(FactoryDWrite, privateFontLoader, privateFontLoader.Key);
                //    //        }

                //    //        _currentFontCollection = privateFontCollection;

                //    //        var family = _currentFontCollection.GetFontFamily(0);
                //    //        // This is generic right now.  We should be able to handle different styles in the future
                //    //        var font = family.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                //    //        _currentFont = font;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //    catch
                //    //    {
                //    //        _currentFont = _defaultFont;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //}

                //    //else
                //    //{
                //    //    _currentFont = _defaultFont;
                //    //    _currentFontSizeEm = fontSize;
                //    //    _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //}
                //}
                //else
                //{
                    _currentFont = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP = ConvertPointSizeToDIP(fontSize);
                //}

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP = ConvertPointSizeToDIP(fontSize);
            }

            fontName = _currentFont.FontFamily.FamilyNames.GetString(0); 
            textFormat = new TextFormat(FactoryDWrite, fontName, 
                _currentFontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, _currentDIP);
            
            GetKerningInfo(charset);

            return _currentFont.ToString();
        }
Пример #17
0
        private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        {

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();
                
                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                    //var contentPath = Path.Combine(appPath, CCApplication.SharedApplication.Content.RootDirectory);
                    //var fontPath = Path.Combine(contentPath, fontName);

                    //if (File.Exists(fontPath))
                    //{
                       // try
                        //{
                            //var fontFileReference = new FontCollection(
                            //_loadedFonts.AddFontFile(fontPath);

                    //        //fontFamily = _loadedFonts.Families[_loadedFonts.Families.Length - 1];

                    //        //_currentFont = new Font(fontFamily, fontSize);
                    //    }
                    //    catch
                    //    {
                    //        _currentFont = _defaultFont;
                    //    }
                    //}
                    //else
                    //{
                        _currentFont = _defaultFont;
                        _currentFontSizeEm = fontSize;
                        _currentDIP = ConvertPointSizeToDIP(fontSize);
                    //}
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP = ConvertPointSizeToDIP(fontSize);
                }

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP = ConvertPointSizeToDIP(fontSize);
            }
            fontName = _currentFont.FontFamily.FamilyNames.GetString(0); 
            textFormat = new TextFormat(FactoryDWrite, fontName, _currentDIP);
            
            GetKerningInfo(charset);

            return _currentFont.ToString();
        }
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties {Hwnd = Handle, PixelSize = ClientSize, PresentOptions = PresentOptions.None};

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(), properties)
                                 {
                                     AntialiasMode = AntialiasMode.PerPrimitive,
                                     TextAntialiasMode = TextAntialiasMode.Cleartype
                                 };

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 0, 0, 0));

            CustomTextRenderer = new CustomTextRenderer(Factory2D, RenderTarget2D);
        }
Пример #19
0
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties();
            properties.Hwnd = renderControl.Handle;
            properties.PixelSize = renderControl.ClientSize;
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);
            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
            RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 0, 0, 0));
        }
Пример #20
0
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            FontCollection fontCollection;

            if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection))
            {
                var ext = Path.GetExtension(fontName);

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        var fileFontLoader     = new FileFontLoader(FactoryDWrite, fontName);
                        var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key);
                        _currentFontCollection = fileFontCollection;
                        fontFamily             = _currentFontCollection.GetFontFamily(0);
                        var ffn = fontFamily.FamilyNames;
                        _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);

                        _fontCollectionCache.Add(fontName, fileFontCollection);
                        _currentFontCollection = fileFontCollection;
                    }
                    catch
                    {
                        _currentFont = GetFont(fontName, fontSize);
                        CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
                    }
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                }
            }
            else
            {
                fontFamily = fontCollection.GetFontFamily(0);

                _currentFont           = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontCollection = fontCollection;
            }

            return(_currentFont);
        }