public QFontRenderOptions CreateClone() { var clone = new QFontRenderOptions(); clone.Colour = Colour; clone.CharacterSpacing = CharacterSpacing; clone.WordSpacing = WordSpacing; clone.LineSpacing = LineSpacing; clone.DropShadowActive = DropShadowActive; clone.DropShadowOffset = DropShadowOffset; clone.DropShadowOpacity = DropShadowOpacity; clone.Monospacing = Monospacing; clone.TransformToViewport = TransformToViewport; clone.LockToPixel = LockToPixel; clone.LockToPixelRatio = LockToPixelRatio; clone.UseDefaultBlendFunction = UseDefaultBlendFunction; clone.JustifyCharacterWeightForExpand = JustifyCharacterWeightForExpand; clone.justifyCharWeightForExpand = justifyCharWeightForExpand; clone.JustifyCharacterWeightForContract = JustifyCharacterWeightForContract; clone.justifyCharWeightForContract = justifyCharWeightForContract; clone.JustifyCapExpand = JustifyCapExpand; clone.JustifyCapContract = JustifyCapContract; clone.JustifyContractionPenalty = JustifyContractionPenalty; return(clone); }
/// <summary> /// Prints the specified text with the given render options /// </summary> /// <param name="font">The <see cref="QFont"/> to print the text with</param> /// <param name="text">The text to print</param> /// <param name="position">The position of the text</param> /// <param name="opt">The text render options</param> /// <returns>The size of the printed text</returns> public SizeF Print(QFont font, ProcessedText text, Vector3 position, QFontRenderOptions opt) { var dp = new QFontDrawingPrimitive(font, opt); DrawingPrimitives.Add(dp); return(dp.Print(text, position, opt.ClippingRectangle)); }
public void MeasureNodes(QFontData fontData, QFontRenderOptions options) { foreach (TextNode node in this) { if (node.Length == 0f) { node.Length = MeasureTextNodeLength(node, fontData, options); } } }
/// <summary> /// Measures each text node using the specified font data and render options /// </summary> /// <param name="fontData">The font data to use for measuring</param> /// <param name="options">The render options</param> public void MeasureNodes(QFontData fontData, QFontRenderOptions options) { foreach (TextNode node in this) { if (Math.Abs(node.Length) < float.Epsilon) { node.Length = MeasureTextNodeLength(node, fontData, options); } } }
private static float TransformWidthToViewport(float input, QFontRenderOptions options) { Viewport?v2 = options.TransformToViewport; if (v2 == null) { return(input); } Viewport?v1 = ViewportHelper.CurrentViewport; Debug.Assert(v1 != null, "v1 != null"); return(input * (v1.Value.Width / v2.Value.Width)); }
private float MeasureTextNodeLength(TextNode node, QFontData fontData, QFontRenderOptions options) { bool monospaced = fontData.IsMonospacingActive(options); float monospaceWidth = fontData.GetMonoSpaceWidth(options); if (node.Type == TextNodeType.Space) { if (monospaced) { return(monospaceWidth); } return((float)Math.Ceiling(fontData.meanGlyphWidth * options.WordSpacing)); } float length = 0f; float height = 0f; if (node.Type == TextNodeType.Word) { for (int i = 0; i < node.Text.Length; i++) { char c = node.Text[i]; if (fontData.CharSetMapping.ContainsKey(c)) { var glyph = fontData.CharSetMapping[c]; if (monospaced) { length += monospaceWidth; } else { length += (float)Math.Ceiling(fontData.CharSetMapping[c].rect.Width + fontData.meanGlyphWidth * options.CharacterSpacing + fontData.GetKerningPairCorrection(i, node.Text, node)); } height = Math.Max(height, glyph.yOffset + glyph.rect.Height); } } } node.Height = height; return(length); }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public static ProcessedText ProcessText(QFont font, QFontRenderOptions options, string text, SizeF maxSize, QFontAlignment alignment) { //TODO: bring justify and alignment calculations in here maxSize.Width = TransformWidthToViewport(maxSize.Width, options); var nodeList = new TextNodeList(text); nodeList.MeasureNodes(font.FontData, options); //we "crumble" words that are two long so that that can be split up var nodesToCrumble = new List <TextNode>(); foreach (TextNode node in nodeList) { if ((!options.WordWrap || node.Length >= maxSize.Width) && node.Type == TextNodeType.Word) { nodesToCrumble.Add(node); } } foreach (TextNode node in nodesToCrumble) { nodeList.Crumble(node, 1); } //need to measure crumbled words nodeList.MeasureNodes(font.FontData, options); var processedText = new ProcessedText(); processedText.textNodeList = nodeList; processedText.maxSize = maxSize; processedText.alignment = alignment; return(processedText); }
private float MeasureTextNodeLength(TextNode node, QFontData fontData, QFontRenderOptions options) { bool monospaced = fontData.IsMonospacingActive(options); float monospaceWidth = fontData.GetMonoSpaceWidth(options); if (node.Type == TextNodeType.Space) { if (monospaced) { return(monospaceWidth); } return((float)Math.Ceiling(fontData.meanGlyphWidth * options.WordSpacing)); } float length = 0f; if (node.Type == TextNodeType.Word) { for (int i = 0; i < node.Text.Length; i++) { char c = node.Text[i]; QFontGlyph glyph; if (fontData.CharSetMapping.TryGetValue(c, out glyph)) { if (monospaced) { length += monospaceWidth; } else { length += (float)Math.Ceiling(glyph.rect.Width + fontData.meanGlyphWidth * options.CharacterSpacing + fontData.GetKerningPairCorrection(i, node.Text, node)); } } } } return(length); }
/// <summary> /// Pushes the specified QFont options onto the options stack /// </summary> /// <param name="newOptions"></param> public void PushOptions(QFontRenderOptions newOptions) { optionsStack.Push(newOptions); }
private void PrintCommentWithLine(QFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset, QFontRenderOptions opts) { yOffset += 20; var dp = new QFontDrawingPimitive(font, opts); //if (doSpacing) // dp.Options.CharacterSpacing = 0.05f; dp.Print(comment, new Vector3(xOffset, Height - yOffset, 0f), new SizeF(Width - 60, -1), alignment); drawing.DrawingPimitiveses.Add(dp); var bounds = font.Measure(comment, new SizeF(Width - 60, float.MaxValue), alignment); //GL.Disable(EnableCap.Texture2D); //GL.Begin(BeginMode.Lines); //GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, 0f); //GL.Color4(1.0f, 0f, 0f, 1f); GL.Vertex2(0f, bounds.Height + 20f); //GL.End(); yOffset += bounds.Height; }
public QFontRenderOptions CreateClone() { var clone = new QFontRenderOptions(); clone.Colour = Colour; clone.CharacterSpacing = CharacterSpacing; clone.WordSpacing = WordSpacing; clone.LineSpacing = LineSpacing; clone.DropShadowActive = DropShadowActive; clone.DropShadowOffset = DropShadowOffset; clone.DropShadowOpacity = DropShadowOpacity; clone.Monospacing = Monospacing; clone.TransformToViewport = TransformToViewport; clone.LockToPixel = LockToPixel; clone.LockToPixelRatio = LockToPixelRatio; clone.UseDefaultBlendFunction = UseDefaultBlendFunction; clone.JustifyCharacterWeightForExpand = JustifyCharacterWeightForExpand; clone.justifyCharWeightForExpand = justifyCharWeightForExpand; clone.JustifyCharacterWeightForContract = JustifyCharacterWeightForContract; clone.justifyCharWeightForContract = justifyCharWeightForContract; clone.JustifyCapExpand = JustifyCapExpand; clone.JustifyCapContract = JustifyCapContract; clone.JustifyContractionPenalty = JustifyContractionPenalty; return clone; }
private void PrintComment(QFont font, string comment, QFontAlignment alignment, ref float yOffset, QFontRenderOptions opts ) { yOffset += 20; var pos = new Vector3(30f, Height - yOffset, 0f); var dp = new QFontDrawingPimitive(font, opts ?? new QFontRenderOptions()); dp.Print(comment, pos, new SizeF(Width - 60, -1), alignment); yOffset += dp.Measure(comment, new SizeF(Width - 60, -1), alignment).Height; drawing.DrawingPimitiveses.Add(dp); }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public static ProcessedText ProcessText(QFont font, QFontRenderOptions options, string text, SizeF maxSize, QFontAlignment alignment) { return(ProcessText(font.FontData, options, text, maxSize, alignment)); }
public QFontDrawingPimitive(QFont font) { _font = font; Options = new QFontRenderOptions(); }
private float MeasureTextNodeLength(TextNode node, QFontData fontData, QFontRenderOptions options) { bool monospaced = fontData.IsMonospacingActive(options); float monospaceWidth = fontData.GetMonoSpaceWidth(options); if (node.Type == TextNodeType.Space) { if (monospaced) return monospaceWidth; return (float)Math.Ceiling(fontData.meanGlyphWidth * options.WordSpacing); } float length = 0f; if (node.Type == TextNodeType.Word) { for (int i = 0; i < node.Text.Length; i++) { char c = node.Text[i]; if (fontData.CharSetMapping.ContainsKey(c)) { if (monospaced) length += monospaceWidth; else length += (float)Math.Ceiling(fontData.CharSetMapping[c].rect.Width + fontData.meanGlyphWidth * options.CharacterSpacing + fontData.GetKerningPairCorrection(i, node.Text, node)); } } } return length; }
public SizeF Print(QFont font, ProcessedText text, Vector3 position, QFontRenderOptions opt) { var dp = new QFontDrawingPimitive(font, opt); DrawingPimitiveses.Add(dp); return dp.Print(text, position, opt.ClippingRectangle); }
private static float TransformWidthToViewport(float input, QFontRenderOptions options) { Viewport? v2 = options.TransformToViewport; if (v2 == null) { return input; } Viewport? v1 = ViewportHelper.CurrentViewport; Debug.Assert(v1 != null, "v1 != null"); return input*(v1.Value.Width/v2.Value.Width); }
/// <summary> /// Creates node list object associated with the text. /// </summary> /// <param name="text"></param> /// <param name="bounds"></param> /// <returns></returns> public static ProcessedText ProcessText(QFont font, QFontRenderOptions options, string text, SizeF maxSize, QFontAlignment alignment) { //TODO: bring justify and alignment calculations in here maxSize.Width = TransformWidthToViewport(maxSize.Width, options); var nodeList = new TextNodeList(text); nodeList.MeasureNodes(font.FontData, options); //we "crumble" words that are two long so that that can be split up var nodesToCrumble = new List<TextNode>(); foreach (TextNode node in nodeList) if ((!options.WordWrap || node.Length >= maxSize.Width) && node.Type == TextNodeType.Word) nodesToCrumble.Add(node); foreach (TextNode node in nodesToCrumble) nodeList.Crumble(node, 1); //need to measure crumbled words nodeList.MeasureNodes(font.FontData, options); var processedText = new ProcessedText(); processedText.textNodeList = nodeList; processedText.maxSize = maxSize; processedText.alignment = alignment; return processedText; }
public void MeasureNodes(QFontData fontData, QFontRenderOptions options){ foreach(TextNode node in this){ if (Math.Abs (node.Length) < float.Epsilon) node.Length = fontData.MeasureTextNodeLength (node, options); } }
public SizeF Print(QFont font, string text, Vector3 position, SizeF maxSize, QFontAlignment alignment, QFontRenderOptions opt ) { var dp = new QFontDrawingPimitive(font, opt); DrawingPimitiveses.Add(dp); return dp.Print(text, position, maxSize, alignment, opt.ClippingRectangle); }
public QFontDrawingPimitive(QFont font) { Font = font.FontData; Options = new QFontRenderOptions(); }
public QFontDrawingPimitive(QFont font, QFontRenderOptions options) { _font = font; Options = options; }
public float GetMonoSpaceWidth(QFontRenderOptions options) { return((float)Math.Ceiling(1 + (1 + options.CharacterSpacing) * meanGlyphWidth)); }
public float GetMonoSpaceWidth(QFontRenderOptions options) { return (float)Math.Ceiling(1 + (1 + options.CharacterSpacing) * meanGlyphWidth); }
public void MeasureNodes(QFontData fontData, QFontRenderOptions options) { foreach(TextNode node in this){ if(node.Length == 0f) node.Length = MeasureTextNodeLength(node,fontData,options); } }
public bool IsMonospacingActive(QFontRenderOptions options) { return((options.Monospacing == QFontMonospacing.Natural && naturallyMonospaced) || options.Monospacing == QFontMonospacing.Yes); }
public void Render(object sender, EventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Spritebatch.Begin(4.0f, view); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { Color col = Color.Black; if (map.colGrid.GetValue(x, y) == CollisionGrid.CollisionType.Solid) { col = Color.Red; } else if (map.colGrid.GetValue(x, y) == CollisionGrid.CollisionType.Platform) { col = Color.Blue; } else if (map.colGrid.GetValue(x, y) == CollisionGrid.CollisionType.Empty) { col = Color.Gray; } Spritebatch.DrawRectangle(new Vector2(x * 32, y * 32), new Vector2(32, 32), col); } } obj.Draw(); Spritebatch.End(); #region Debug Text QFont.Begin(); QFontRenderOptions op = new QFontRenderOptions(); op.Colour = Color.White; font.PushOptions(op); font.Print(String.Format( "vx={0} vy={1}\ng {2}\nl {3}\npx={4} py={5}", Math.Round(obj.velocity.X, 1), Math.Round(obj.velocity.Y, 1), obj.IsOnGround, obj.ColLeft, Math.Round(obj.position.X, 1), Math.Round(obj.position.Y, 1))); QFont.End(); #endregion window.SwapBuffers(); }
/// <summary> /// Prints the specified text with the given maximum size, alignment and render options /// </summary> /// <param name="font">The <see cref="QFont"/> to print the text with</param> /// <param name="text">The text to print</param> /// <param name="position">The position of the text</param> /// <param name="maxSize">The maximum bounding size of the text</param> /// <param name="alignment">The text alignment</param> /// <param name="opt">The render options</param> /// <returns>The size of the printed text</returns> public SizeF Print(QFont font, string text, Vector3 position, SizeF maxSize, QFontAlignment alignment, QFontRenderOptions opt) { var dp = new QFontDrawingPrimitive(font, opt); DrawingPrimitives.Add(dp); return(dp.Print(text, position, maxSize, alignment, opt.ClippingRectangle)); }
public bool IsMonospacingActive(QFontRenderOptions options) { return (options.Monospacing == QFontMonospacing.Natural && naturallyMonospaced) || options.Monospacing == QFontMonospacing.Yes; }
/// <summary>Load resources here.</summary> /// <param name="e">Not used.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.Keyboard.KeyDown += KeyDown; drawing = new QFontDrawing(); controlsDrawing = new QFontDrawing(); controlsTextOpts = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.8f, 0.1f, 0.1f, 1.0f).ToArgb()), DropShadowActive = true }; heading2 = new QFont("woodenFont.qfont", new QFontConfiguration(addDropShadow: true), 1.0f); heading2Options = new QFontRenderOptions() { Colour = Color.White, DropShadowActive = true}; var builderConfig = new QFontBuilderConfiguration(addDropShadow: true); builderConfig.ShadowConfig.blurRadius = 2; //reduce blur radius because font is very small builderConfig.ShadowConfig.blurPasses = 1; builderConfig.ShadowConfig.Type = ShadowType.Blurred; builderConfig.TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit; //best render hint for this font mainText = new QFont("Fonts/times.ttf", 14, builderConfig); mainTextOptions = new QFontRenderOptions() { DropShadowActive = true, Colour = Color.White, WordSpacing = 0.5f}; _benchmarkResults = new QFont("Fonts/times.ttf", 14, builderConfig); heading1 = new QFont("Fonts/HappySans.ttf", 72, new QFontBuilderConfiguration(true)); controlsText = new QFont("Fonts/HappySans.ttf", 32, new QFontBuilderConfiguration(true)); codeText = new QFont("Fonts/Comfortaa-Regular.ttf", 12, new QFontBuilderConfiguration()); heading1Options = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.2f, 0.2f, 0.2f, 1.0f).ToArgb()), DropShadowActive = true}; _processedText = QFontDrawingPimitive.ProcessText(mainText, mainTextOptions, preProcessed, new SizeF(Width - 40, -1), QFontAlignment.Justify); codeTextOptions = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.0f, 0.0f, 0.4f, 1.0f).ToArgb()) }; monoSpaced = new QFont("Fonts/Anonymous.ttf", 10, new QFontBuilderConfiguration()); monoSpacedOptions = new QFontRenderOptions() { Colour = Color.FromArgb(new Color4(0.1f, 0.1f, 0.1f, 1.0f).ToArgb()), DropShadowActive = true}; GL.ClearColor(Color4.CornflowerBlue); }