Пример #1
0
 public Renderer()
 {
     _fontLoader   = new FontLoader();
     _textMeasurer = new HyperfontTextMeasurer(_fontLoader);
     _typesetter   = new Typesetter(_textMeasurer);
     _exporter     = new PNGExporter(_fontLoader);
     _parser       = new LaTeXParser();
 }
Пример #2
0
        public MySlimDG(ShanghaiEXE wind)
        {
            this.direct3D    = new Direct3D();
            this.form        = wind;
            this.DisplayMode = false;
            this.SetParam();
            this.CreateDevice(wind, this.param);
            this.SetView();
            this.sprite = new Sprite(this.device);
            GraphicsClass.Direct3DDevice = this.device;
            GraphicsClass.Direct3DSprite = this.sprite;
            this.tex = new Textures(wind);
            this.tex.ProgressUpdated += this.TCDLoad_ProgressUpdate;
            this.thread_1             = new Thread(new ThreadStart(this.tex.Tex));
            this.thread_1.Start();

            var usedFont      = default(Font);
            var usedMiniFont  = default(Font);
            var usedMicroFont = default(Font);

            if ((new InstalledFontCollection().Families).Any(f => f.Name == "Microsoft Sans Serif"))
            {
                usedFont      = new Font("Microsoft Sans Serif", 10f, FontStyle.Regular);
                usedMiniFont  = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular);
                usedMicroFont = new Font("Microsoft Sans Serif", 8f, FontStyle.Regular);
            }
            else
            {
                MySlimDG.customFontInstance = new PrivateFontCollection();
                var    assembly     = Assembly.GetExecutingAssembly();
                string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("JF-Dot-jiskan16s.ttf", StringComparison.InvariantCultureIgnoreCase));
                byte[] fontBytes;
                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                {
                    fontBytes = new byte[stream.Length];
                    stream.Read(fontBytes, 0, fontBytes.Length);
                    stream.Close();
                }
                IntPtr handle = Marshal.AllocCoTaskMem(fontBytes.Length);
                Marshal.Copy(fontBytes, 0, handle, fontBytes.Length);
                MySlimDG.customFontInstance.AddMemoryFont(handle, fontBytes.Length);
                Marshal.FreeCoTaskMem(handle);
                usedFont      = new Font(MySlimDG.customFontInstance.Families[0], 12, FontStyle.Regular);
                usedMiniFont  = new Font(MySlimDG.customFontInstance.Families[0], 10, FontStyle.Regular);
                usedMicroFont = new Font(MySlimDG.customFontInstance.Families[0], 10, FontStyle.Regular);
            }

            this.font      = new SlimFont(usedFont);
            this.minifont  = new SlimFont(usedMiniFont);
            this.microfont = new SlimFont(usedMicroFont);

            this.measurer = new DGTextMeasurer(usedFont, usedMiniFont, usedMicroFont);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgRenderContext" /> class.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="isDocument">Create an SVG document if set to <c>true</c>.</param>
        /// <param name="textMeasurer">The text measurer.</param>
        /// <param name="background">The background.</param>
        public SvgRenderContext(Stream s, double width, double height, bool isDocument, ITextMeasurer textMeasurer, OxyColor background)
        {
            if (textMeasurer == null)
            {
                throw new ArgumentNullException("textMeasurer", "A text measuring render context must be provided.");
            }

            this.w = new SvgWriter(s, width, height, isDocument);
            this.TextMeasurer = textMeasurer;
            if (background != null)
            {
                this.w.WriteRectangle(0, 0, width, height, this.w.CreateStyle(background, null, 0));
            }
        }
Пример #4
0
        public OpenGLRenderer(string tcdFile, string password, string graphicsFormat, double initialScaleX, double initialScaleY)
        {
            var loadStrategy = new TCDLoadStrategy(tcdFile, password, graphicsFormat);

            //var loadStrategy = new FolderTextureLoadStrategy("Graphics/{0}.png");
            loadStrategy.ProgressUpdated += this.Load_ProgressUpdate;
            loadStrategy.Load();
            this.renderer    = new SpriteRendererPanel(loadStrategy, initialScaleX, initialScaleY);
            this.lastWasText = false;

            var usedFont      = default(Font);
            var usedMiniFont  = default(Font);
            var usedMicroFont = default(Font);

            if ((new InstalledFontCollection().Families).Any(f => f.Name == "Microsoft Sans Serif"))
            {
                usedFont      = new Font("Microsoft Sans Serif", 15f, FontStyle.Regular);
                usedMiniFont  = new Font("Microsoft Sans Serif", 12f, FontStyle.Regular);
                usedMicroFont = new Font("Microsoft Sans Serif", 11f, FontStyle.Regular);
            }
            else
            {
                this.customFontInstance = new PrivateFontCollection();
                var    assembly     = Assembly.GetExecutingAssembly();
                string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith(OpenGLRenderer.FallbackFont, StringComparison.InvariantCultureIgnoreCase));
                byte[] fontBytes;
                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                {
                    fontBytes = new byte[stream.Length];
                    stream.Read(fontBytes, 0, fontBytes.Length);
                    stream.Close();
                }
                IntPtr handle = Marshal.AllocCoTaskMem(fontBytes.Length);
                Marshal.Copy(fontBytes, 0, handle, fontBytes.Length);
                this.customFontInstance.AddMemoryFont(handle, fontBytes.Length);
                Marshal.FreeCoTaskMem(handle);
                usedFont      = new Font(this.customFontInstance.Families[0], 15, FontStyle.Regular);
                usedMiniFont  = new Font(this.customFontInstance.Families[0], 12, FontStyle.Regular);
                usedMicroFont = new Font(this.customFontInstance.Families[0], 11, FontStyle.Regular);
            }

            this.regularFont = usedFont;
            this.miniFont    = usedMiniFont;
            this.microFont   = usedMicroFont;

            this.measurer = new GLTextMeasurer(usedFont, usedMiniFont, usedMicroFont);
        }
Пример #5
0
        public void InitializeData()
        {
            this.loading.LoadComplete += this.Loading_LoadComplete;

            this.UpdateLoadingText(LoadType.Data, 100);
            this.UpdateLoadingText(LoadType.Graphics, 0);
            switch (ShanghaiEXE.Config.RenderEngine)
            {
            case "DirectX9":
                var dgRenderer = new MySlimDG(this);
                dgRenderer.ProgressUpdated += this.TextureLoad_ProgressUpdate;
                this.dg = dgRenderer;
                break;

            case "OpenGL":
                var renderControl = new OpenGLRenderer("ShaGResource.tcd", "sasanasi", "{0}.png", this.scaleFactorX, this.scaleFactorY);
                renderControl.GetPanel().SetSize(Constants.ScreenSize);
                renderControl.ProgressUpdated += this.TextureLoad_ProgressUpdate;
                this.dg = renderControl;
                var renderPanel = renderControl.GetPanel();
                if (ShanghaiEXE.Config.Fullscreen)
                {
                    renderPanel.SizeChanged += (s, e) =>
                    {
                        renderPanel.Location = new Point((this.Width - renderPanel.Width) / 2, (this.Height - renderPanel.Height) / 2);
                    };
                    this.SizeChanged += (s, e) =>
                    {
                        renderPanel.Location = new Point((this.Width - renderPanel.Width) / 2, (this.Height - renderPanel.Height) / 2);
                    };
                }
                this.Controls.Add(renderPanel);
                this.BackColor = Color.Black;
                break;
            }
            ShanghaiEXE.measurer = this.dg.GetTextMeasurer();

            this.UpdateLoadingText(LoadType.Audio, 25);
            switch (ShanghaiEXE.Config.AudioEngine)
            {
            case "DirectSound":
                this.ad = new MyAudio(this.volSE);
                break;

            case "OpenAL":
                this.ad = new OpenALAudio(this.volSE, "ShaSResource.tcd", "sasanasi", "{0}.wav");
                break;
            }
            this.ad.BGMVolume         = this.volBGM;
            this.ad.SoundEffectVolume = this.volSE;
            this.ad.ProgressUpdated  += this.AudioLoad_ProgressUpdate;
            this.UpdateLoadingText(LoadType.Audio, 100);

            this.UpdateLoadingText(LoadType.Device, 25);
            this.mk = new MyKeyBoard(this);
            this.co = new Controller(this);
            Input.FormSetting(this);
            this.UpdateLoadingText(LoadType.Device, 100);

            this.UpdateLoadingText(LoadType.Save, 25);
            this.savedata = new SaveData();
            this.savedata.Init();
            this.UpdateLoadingText(LoadType.Save, 50);
            this.savedata.Load(this);
            this.UpdateLoadingText(LoadType.Save, 100);
        }
Пример #6
0
 public TypesetterTests()
 {
     _textMeasurer = new TestTextMeasurer();
     _typesetter   = new Typesetter(_textMeasurer);
 }
 public Typesetter(ITextMeasurer textMeasurer)
 {
     _textMeasurer = textMeasurer;
 }
Пример #8
0
 /// <summary>
 /// Exports the specified model to a stream.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="stream">The output stream.</param>
 /// <param name="width">The width (points).</param>
 /// <param name="height">The height (points).</param>
 /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param>
 /// <param name="textMeasurer">The text measurer.</param>
 public static void Export(PlotModel model, Stream stream, double width, double height, bool isDocument, ITextMeasurer textMeasurer)
 {
     using (var rc = new SvgRenderContext(stream, width, height, true, textMeasurer, model.Background))
     {
         model.Update();
         model.Render(rc, width, height);
         rc.Complete();
         rc.Flush();
     }
 }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgRenderContext" /> class.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="isDocument">Create an SVG document if set to <c>true</c>.</param>
        /// <param name="textMeasurer">The text measurer.</param>
        /// <param name="background">The background.</param>
        public SvgRenderContext(Stream s, double width, double height, bool isDocument, ITextMeasurer textMeasurer, OxyColor background)
        {
            if (textMeasurer == null)
            {
                throw new ArgumentNullException("textMeasurer", "A text measuring render context must be provided.");
            }

            this.w            = new SvgWriter(s, width, height, isDocument);
            this.TextMeasurer = textMeasurer;
            if (background != null)
            {
                this.w.WriteRectangle(0, 0, width, height, this.w.CreateStyle(background, null, 0));
            }
        }