private void setFontStyle(RichTextBox rtb, FontStyle style) { if (rtb.SelectionLength == 0) setCharFontStyle(rtb, style); else { // to avoid screen refreshing, we create a fake RichTextBox using (RichTextBox a = new RichTextBox()) { a.SuspendLayout(); a.SelectedRtf = rtb.SelectedRtf; a.SelectAll(); int selectionStart = a.SelectionStart; int selectionLength = a.SelectionLength; int selectionEnd = selectionStart + selectionLength; for (int x = selectionStart; x < selectionEnd; ++x) { // Set temporary selection a.Select(x, 1); // Toggle font style of the selection setCharFontStyle(a, style); } // Restore the original selection a.SelectAll(); rtb.SelectedRtf = a.SelectedRtf; } } }
public CreateFontArgs(string name, float size, FontStyle style, GraphicsUnit unit) { Name = String.IsNullOrWhiteSpace(name) ? FontFactory.GenericSansSerif : name; Size = size; Style = style; Unit = unit; }
public Engine_Font(string typeFace, float size, FontStyle fontStyle) { using (GDIFont gdiFont = new GDIFont(typeFace, size, fontStyle)) { m_Font = new D3DFont(Engine_Game.DGDevice, gdiFont); } }
public FontMetrics(Graphics g, Font f) { _f = f; _ffm = f.FontFamily; _fs = f.Style; _g = g; }
public void Set(TextBlock textBlock) { this.fontFamily = textBlock.FontFamily; this.fontWeight = textBlock.FontWeight; this.fontStyle = textBlock.FontStyle; this.fontStretch = textBlock.FontStretch; }
/// <summary>Used to create the font with the style and size requested.</summary> /// <param name="p_fstStyle">The style of font to create.</param> /// <param name="p_fltSize">The size of font to create.</param> /// <returns>The font created.</returns> public Font CreateFont(FontStyle p_fstStyle, float p_fltSize) { if (m_dicFamilyCache.ContainsKey(p_fstStyle)) return new Font(m_dicFamilyCache[p_fstStyle], p_fltSize, p_fstStyle); Font fntFont = null; foreach (string strFontFamily in Families) { try { fntFont = FontManager.GetFont(strFontFamily, p_fltSize, p_fstStyle); if (fntFont == null) fntFont = new Font(strFontFamily, p_fltSize, p_fstStyle); } catch { //the font doesn't work for some reason - keep looking } if (fntFont != null) { m_dicFamilyCache[p_fstStyle] = fntFont.FontFamily; return fntFont; } } return null; }
public FormattedTextImpl(string text, string fontFamilyName, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight, TextWrapping wrapping) { _text = text ?? string.Empty; // Replace 0 characters with zero-width spaces (200B) _text = _text.Replace((char)0, (char)0x200B); var typeface = TypefaceCache.GetTypeface(fontFamilyName, fontStyle, fontWeight); _paint = new SKPaint(); //currently Skia does not measure properly with Utf8 !!! //Paint.TextEncoding = SKTextEncoding.Utf8; _paint.TextEncoding = SKTextEncoding.Utf16; _paint.IsStroke = false; _paint.IsAntialias = true; _paint.LcdRenderText = true; _paint.SubpixelText = true; _paint.Typeface = typeface; _paint.TextSize = (float)fontSize; _paint.TextAlign = textAlignment.ToSKTextAlign(); _wrapping = wrapping; Rebuild(); }
public SccPositionAndStyle(Color color, FontStyle style, int y, int x) { ForeColor = color; Style = style; X = x; Y = y; }
static void Load () { mLoaded = true; mPartial = EditorPrefs.GetString("NGUI Partial"); mFontName = EditorPrefs.GetString("NGUI Font Name"); mAtlasName = EditorPrefs.GetString("NGUI Atlas Name"); mFontData = GetObject("NGUI Font Asset") as TextAsset; mFontTexture = GetObject("NGUI Font Texture") as Texture2D; mFont = GetObject("NGUI Font") as UIFont; mAtlas = GetObject("NGUI Atlas") as UIAtlas; mAtlasPadding = EditorPrefs.GetInt("NGUI Atlas Padding", 1); mAtlasTrimming = EditorPrefs.GetBool("NGUI Atlas Trimming", true); mAtlasPMA = EditorPrefs.GetBool("NGUI Atlas PMA", true); mUnityPacking = EditorPrefs.GetBool("NGUI Unity Packing", true); mForceSquare = EditorPrefs.GetBool("NGUI Force Square Atlas", true); mPivot = (UIWidget.Pivot)EditorPrefs.GetInt("NGUI Pivot", (int)mPivot); mLayer = EditorPrefs.GetInt("NGUI Layer", -1); mDynFont = GetObject("NGUI DynFont") as Font; mDynFontSize = EditorPrefs.GetInt("NGUI DynFontSize", 16); mDynFontStyle = (FontStyle)EditorPrefs.GetInt("NGUI DynFontStyle", (int)FontStyle.Normal); if (mLayer < 0 || string.IsNullOrEmpty(LayerMask.LayerToName(mLayer))) mLayer = -1; if (mLayer == -1) mLayer = LayerMask.NameToLayer("UI"); if (mLayer == -1) mLayer = LayerMask.NameToLayer("GUI"); if (mLayer == -1) mLayer = 5; EditorPrefs.SetInt("UI Layer", mLayer); LoadColor(); }
public DrawStringContext(string text, int thickness, Color color, FontStyle fontStyle) { _Thickness = thickness; _Text = text; _Color = color; _FontStyle = fontStyle; }
/// <summary> /// Initializes a new instance of the <see cref="RichTextBoxRowColoringRule" /> class. /// </summary> /// <param name="condition">The condition.</param> /// <param name="fontColor">Color of the foregroung text.</param> /// <param name="backColor">Color of the background text.</param> /// <param name="fontStyle">The font style.</param> public RichTextBoxRowColoringRule(string condition, string fontColor, string backColor, FontStyle fontStyle) { this.Condition = condition; this.FontColor = fontColor; this.BackgroundColor = backColor; this.Style = fontStyle; }
public FormattedText( string text, string fontFamilyName, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { this.Text = text; this.FontFamilyName = fontFamilyName; this.FontSize = fontSize; this.FontStyle = fontStyle; this.FontWeight = fontWeight; this.TextAlignment = textAlignment; var platform = Locator.Current.GetService<IPlatformRenderInterface>(); this.PlatformImpl = platform.CreateFormattedText( text, fontFamilyName, fontSize, fontStyle, textAlignment, fontWeight); }
private void CreateFont (string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical) { #if ONLY_1_1 if (familyName == null) throw new ArgumentNullException ("familyName"); #endif originalFontName = familyName; FontFamily family; // NOTE: If family name is null, empty or invalid, // MS creates Microsoft Sans Serif font. try { family = new FontFamily (familyName); } catch (Exception){ family = FontFamily.GenericSansSerif; } setProperties (family, emSize, style, unit, charSet, isVertical); Status status = GDIPlus.GdipCreateFont (family.NativeObject, emSize, style, unit, out fontObject); if (status == Status.FontStyleNotFound) throw new ArgumentException (Locale.GetText ("Style {0} isn't supported by font {1}.", style.ToString (), familyName)); GDIPlus.CheckStatus (status); }
public Typeface(FontFamily fontFamily, FontStyle style = FontStyle.Normal, FontWeight weight = FontWeight.Normal, FontStretch stretch = FontStretch.Normal) { this.FontFamily = fontFamily; this.Style = style; this.Weight = weight; this.Stretch = stretch; }
public FormattedTextImpl( string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { var factory = Locator.Current.GetService<DWrite.Factory>(); var format = new DWrite.TextFormat( factory, fontFamily, (DWrite.FontWeight)fontWeight, (DWrite.FontStyle)fontStyle, (float)fontSize); TextLayout = new DWrite.TextLayout( factory, text ?? string.Empty, format, float.MaxValue, float.MaxValue); TextLayout.TextAlignment = textAlignment.ToDirect2D(); }
/// <summary> /// Initializes a new instance of the <see cref="RichTextBoxWordColoringRule" /> class. /// </summary> /// <param name="text">The text to be matched..</param> /// <param name="textColor">Color of the text.</param> /// <param name="backgroundColor">Color of the background.</param> /// <param name="fontStyle">The font style.</param> public RichTextBoxWordColoringRule(string text, string textColor, string backgroundColor, FontStyle fontStyle) { this.Text = text; this.FontColor = textColor; this.BackgroundColor = backgroundColor; this.Style = fontStyle; }
public FormattedTextImpl( Pango.Context context, string text, string fontFamily, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { Contract.Requires<ArgumentNullException>(context != null); Contract.Requires<ArgumentNullException>(text != null); Layout = new Pango.Layout(context); _text = text; Layout.SetText(text); Layout.FontDescription = new Pango.FontDescription { Family = fontFamily, Size = Pango.Units.FromDouble(CorrectScale(fontSize)), Style = (Pango.Style)fontStyle, Weight = fontWeight.ToCairo() }; Layout.Alignment = textAlignment.ToCairo(); Layout.Attributes = new Pango.AttrList(); }
public LWTreeView() : base() { this.originalFont = (Font)this.Font.Clone(); this.originalFontStyle = this.originalFont.Style; this.Scrollable = Configurations.useListScrolling; if (Configurations.resetLWTreeViewFonts) { this.MouseDown += new MouseEventHandler(LWTreeView_MouseDown); } if (Configurations.provideDummyMouseHandlers) { this.MouseCaptureChanged += new EventHandler(LWTreeView_MouseCaptureChanged); this.MouseClick += new MouseEventHandler(LWTreeView_MouseClick); this.MouseDoubleClick += new MouseEventHandler(LWTreeView_MouseDoubleClick); this.MouseEnter += new EventHandler(LWTreeView_MouseEnter); this.MouseHover += new EventHandler(LWTreeView_MouseHover); this.MouseLeave += new EventHandler(LWTreeView_MouseMove); this.MouseMove += new MouseEventHandler(LWTreeView_MouseMove); this.MouseUp += new MouseEventHandler(LWTreeView_MouseUp); this.MouseWheel += new MouseEventHandler(LWTreeView_MouseWheel); this.NodeMouseClick += new TreeNodeMouseClickEventHandler(LWTreeView_NodeMouseClick); this.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(LWTreeView_NodeMouseDoubleClick); this.NodeMouseHover += new TreeNodeMouseHoverEventHandler(LWTreeView_NodeMouseHover); } }
public static Font CreateFont(Font fBase, FontStyle fs) { try { return new Font(fBase, fs); } catch(Exception) { Debug.Assert(false); } // Style unsupported? return new Font(fBase, fBase.Style); // Clone }
public AppearanceDescription(string name, Color foreColor, Color backColor, FontStyle fontStyle) { Text = name; ForeColor = foreColor; BackColor = backColor; FontStyle = fontStyle; }
public override object SetStyle (object handle, FontStyle style) { FontDescription fd = (FontDescription) handle; fd = fd.Copy (); fd.Style = (Pango.Style)(int)style; return fd; }
public static Font CreateFont(FontFamily ff, float fEmSize, FontStyle fs) { try { return new Font(ff, fEmSize, fs); } catch(Exception) { Debug.Assert(false); } // Style unsupported? return new Font(ff, fEmSize); }
public static Font GetFont(string fontFamilyName, float pointSize, FontStyle style) { string key = createHashString(fontFamilyName, pointSize, style); try { if (fontCollection.ContainsKey(key)) { Font font = fontCollection[key]; if (font != null) { return font; } } } catch (Exception) { } Font font2 = getFont(fontFamilyName, pointSize, style); if (font2 == null) { font2 = GetFont("Microsoft Sans Serif", pointSize, style); } if ((font2 != null) && dpiSet) { fontCollection.Add(key, font2); } return font2; }
/// <summary> /// 利用颜色和大小,在指定点绘制文字 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="text"></param> /// <param name="color"></param> /// <param name="fontSize"></param> public static void DrawText(float x, float y, object text, Color color, int fontSize = 10, FontStyle style = FontStyle.Normal) { _usingGuiStyle.normal.textColor = color; _usingGuiStyle.fontSize = fontSize; _usingGuiStyle.fontStyle = style; GUI.Label(new Rect(x, y, 0, 0), text.ToString(), _usingGuiStyle); }
public QFont(string fileName, float size, FontStyle style, QFontBuilderConfiguration config) { PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile(fileName); var fontFamily = pfc.Families[0]; if (!fontFamily.IsStyleAvailable(style)) throw new ArgumentException("Font file: " + fileName + " does not support style: " + style ); if (config == null) config = new QFontBuilderConfiguration(); TransformViewport? transToVp = null; float fontScale = 1f; if (config.TransformToCurrentOrthogProjection) transToVp = OrthogonalTransform(out fontScale); using(var font = new Font(fontFamily, size * fontScale * config.SuperSampleLevels, style)){ fontData = BuildFont(font, config, null); } if (config.ShadowConfig != null) Options.DropShadowActive = true; if (transToVp != null) Options.TransformToViewport = transToVp; if(config.UseVertexBuffer) InitVBOs(); }
public FontKey(string fontname, float fontSize, FontStyle fs) { //font name/ not filename this.FontNameIndex = RegisterFontName(fontname.ToLower()); this.FontSize = fontSize; this.FontStyle = fs; }
/// <summary> /// Converts a <see cref="FontStyle"/> to <see cref="CFM"/> constant. /// </summary> /// <param name="fontStyle">The <see cref="FontStyle"/> to convert.</param> /// <returns>A <see cref="CFM"/> constant</returns> public static CFM FontStyleTo_CFM(FontStyle fontStyle) { CFM cfm_ = 0; if ((fontStyle & FontStyle.Bold) == FontStyle.Bold) { cfm_ |= CFM.BOLD; } if ((fontStyle & FontStyle.Italic) == FontStyle.Italic) { cfm_ |= CFM.ITALIC; } if ((fontStyle & FontStyle.Strikeout) == FontStyle.Strikeout) { cfm_ |= CFM.STRIKEOUT; } if ((fontStyle & FontStyle.Underline) == FontStyle.Underline) { cfm_ |= CFM.UNDERLINE; } return cfm_; }
/// <summary> /// The default constructor. /// </summary> /// <param name="name">The name of the font.</param> /// <param name="style">The style of the font.</param> /// <param name="size">The point-size of the font.</param> public Font(string name, FontStyle style, double size) { this.Name = name; this.Style = style; this.Size = (float)size; LoadedFonts.Add(name, this); }
public Typeface(FontFamily fontFamily, FontStyle style, FontWeight weight, FontStretch stretch) { this.FontFamily = fontFamily; this.Style = style; this.Weight = weight; this.Stretch = stretch; }
/// <summary> /// Initializes a new instance of the <see cref="FormattedText"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="fontFamilyName">The font family.</param> /// <param name="fontSize">The font size.</param> /// <param name="fontStyle">The font style.</param> /// <param name="textAlignment">The text alignment.</param> /// <param name="fontWeight">The font weight.</param> public FormattedText( string text, string fontFamilyName, double fontSize, FontStyle fontStyle, TextAlignment textAlignment, FontWeight fontWeight) { Contract.Requires<ArgumentNullException>(text != null); Contract.Requires<ArgumentNullException>(fontFamilyName != null); Contract.Requires<ArgumentException>(fontSize > 0); Text = text; FontFamilyName = fontFamilyName; FontSize = fontSize; FontStyle = fontStyle; FontWeight = fontWeight; TextAlignment = textAlignment; var platform = PerspexLocator.Current.GetService<IPlatformRenderInterface>(); if (platform == null) { throw new Exception("Could not create FormattedText: IPlatformRenderInterface not registered."); } PlatformImpl = platform.CreateFormattedText( text, fontFamilyName, fontSize, fontStyle, textAlignment, fontWeight); }
override public void OnInspectorGUI() { mFont = target as UIFont; EditorGUIUtility.LookLikeControls(80f); NGUIEditorTools.DrawSeparator(); if (mFont.replacement != null) { mType = FontType.Reference; mReplacement = mFont.replacement; } else if (mFont.dynamicFont != null) { mType = FontType.Dynamic; } GUILayout.BeginHorizontal(); FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (mType != fontType) { if (fontType == FontType.Normal) { OnSelectFont(null); } else { mType = fontType; } if (mType != FontType.Dynamic && mFont.dynamicFont != null) { mFont.dynamicFont = null; } } if (mType == FontType.Reference) { ComponentSelector.Draw <UIFont>(mFont.replacement, OnSelectFont); NGUIEditorTools.DrawSeparator(); GUILayout.Label("You can have one font simply point to\n" + "another one. This is useful if you want to be\n" + "able to quickly replace the contents of one\n" + "font with another one, for example for\n" + "swapping an SD font with an HD one, or\n" + "replacing an English font with a Chinese\n" + "one. All the labels referencing this font\n" + "will update their references to the new one."); if (mReplacement != mFont && mFont.replacement != mReplacement) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.replacement = mReplacement; UnityEditor.EditorUtility.SetDirty(mFont); } return; } else if (mType == FontType.Dynamic) { #if UNITY_3_5 EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error); #else NGUIEditorTools.DrawSeparator(); Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font; if (fnt != mFont.dynamicFont) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFont = fnt; } GUILayout.BeginHorizontal(); int size = EditorGUILayout.IntField("Size", mFont.dynamicFontSize, GUILayout.Width(120f)); FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (size != mFont.dynamicFontSize) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFontSize = size; } if (style != mFont.dynamicFontStyle) { NGUIEditorTools.RegisterUndo("Font change", mFont); mFont.dynamicFontStyle = style; } Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } #endif } else { NGUIEditorTools.DrawSeparator(); ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas); if (mFont.atlas != null) { if (mFont.bmFont.isValid) { NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false); } EditorGUILayout.Space(); } else { // No atlas specified -- set the material and texture rectangle directly Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material; if (mFont.material != mat) { NGUIEditorTools.RegisterUndo("Font Material", mFont); mFont.material = mat; } } // For updating the font's data when importing from an external source, such as the texture packer bool resetWidthHeight = false; if (mFont.atlas != null || mFont.material != null) { TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset; if (data != null) { NGUIEditorTools.RegisterUndo("Import Font Data", mFont); BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes); mFont.MarkAsDirty(); resetWidthHeight = true; Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters"); } } if (mFont.bmFont.isValid) { Color green = new Color(0.4f, 1f, 0f, 1f); Texture2D tex = mFont.texture; if (tex != null) { if (mFont.atlas == null) { // Pixels are easier to work with than UVs Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false); // Automatically set the width and height of the rectangle to be the original font texture's dimensions if (resetWidthHeight) { pixels.width = mFont.texWidth; pixels.height = mFont.texHeight; } // Font sprite rectangle GUI.backgroundColor = green; pixels = EditorGUILayout.RectField("Pixel Rect", pixels); GUI.backgroundColor = Color.white; // Create a button that can make the coordinates pixel-perfect on click GUILayout.BeginHorizontal(); { Rect corrected = NGUIMath.MakePixelPerfect(pixels); if (corrected == pixels) { GUI.color = Color.grey; GUILayout.Button("Make Pixel-Perfect"); GUI.color = Color.white; } else if (GUILayout.Button("Make Pixel-Perfect")) { pixels = corrected; GUI.changed = true; } } GUILayout.EndHorizontal(); // Convert the pixel coordinates back to UV coordinates Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height); if (mFont.uvRect != uvRect) { NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont); mFont.uvRect = uvRect; } //NGUIEditorTools.DrawSeparator(); EditorGUILayout.Space(); } } } } // The font must be valid at this point for the rest of the options to show up if (mFont.isDynamic || mFont.bmFont.isValid) { // Font spacing GUILayout.BeginHorizontal(); { EditorGUIUtility.LookLikeControls(0f); GUILayout.Label("Spacing", GUILayout.Width(60f)); GUILayout.Label("X", GUILayout.Width(12f)); int x = EditorGUILayout.IntField(mFont.horizontalSpacing); GUILayout.Label("Y", GUILayout.Width(12f)); int y = EditorGUILayout.IntField(mFont.verticalSpacing); GUILayout.Space(18f); EditorGUIUtility.LookLikeControls(80f); if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y) { NGUIEditorTools.RegisterUndo("Font Spacing", mFont); mFont.horizontalSpacing = x; mFont.verticalSpacing = y; } } GUILayout.EndHorizontal(); if (mFont.atlas == null) { mView = View.Font; mUseShader = false; float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f)); if (pixelSize != mFont.pixelSize) { NGUIEditorTools.RegisterUndo("Font Change", mFont); mFont.pixelSize = pixelSize; } } EditorGUILayout.Space(); } // Preview option if (!mFont.isDynamic && mFont.atlas != null) { GUILayout.BeginHorizontal(); { mView = (View)EditorGUILayout.EnumPopup("Preview", mView); GUILayout.Label("Shader", GUILayout.Width(45f)); mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)); } GUILayout.EndHorizontal(); } // Dynamic fonts don't support emoticons if (!mFont.isDynamic && mFont.bmFont.isValid) { if (mFont.atlas != null) { NGUIEditorTools.DrawHeader("Symbols and Emoticons"); List <BMSymbol> symbols = mFont.symbols; for (int i = 0; i < symbols.Count;) { BMSymbol sym = symbols[i]; GUILayout.BeginHorizontal(); GUILayout.Label(sym.sequence, GUILayout.Width(40f)); if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite)) { mSelectedSymbol = sym; } if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (mFont.atlas != null) { EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName); NGUIEditorTools.Select(mFont.atlas.gameObject); } } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { NGUIEditorTools.RegisterUndo("Remove symbol", mFont); mSymbolSequence = sym.sequence; mSymbolSprite = sym.spriteName; symbols.Remove(sym); mFont.MarkAsDirty(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(4f); ++i; } if (symbols.Count > 0) { NGUIEditorTools.DrawSeparator(); } GUILayout.BeginHorizontal(); mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f)); NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite); bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite); GUI.backgroundColor = isValid ? Color.green : Color.grey; if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid) { NGUIEditorTools.RegisterUndo("Add symbol", mFont); mFont.AddSymbol(mSymbolSequence, mSymbolSprite); mFont.MarkAsDirty(); mSymbolSequence = ""; mSymbolSprite = ""; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (symbols.Count == 0) { EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info); } else { GUILayout.Space(4f); } } } }
public bool IsStyleAvailable(FontStyle fontStyle) { return(NativeStyleAvailable(fontStyle)); }
public void AppendLine(string str, FontStyle fs) { Append(str, fs); m_sb.AppendLine(); }
public void AppendLine(string str, FontStyle fs, string strOuterPrefix, string strInnerPrefix, string strInnerSuffix, string strOuterSuffix) { Append(str, fs, strOuterPrefix, strInnerPrefix, strInnerSuffix, strOuterSuffix); m_sb.AppendLine(); }
public void Append(string str, FontStyle fs) { Append(str, fs, null, null, null, null); }
void Render(Element element, Section box) { foreach (var child in element.ChildNodes) { switch (child.NodeType) { case NodeType.Text: FillBuffer((TextNode)child); break; case NodeType.Element: var node = (Element)child; switch (node.TagName) { case "script": case "style": break; case "img": FillBuffer(Render((HTMLImageElement)node)); break; case "b": case "strong": { var previous = currentFontWeight; currentFontWeight = FontWeights.Bold; Render(node, box); currentFontWeight = previous; } break; case "i": { var previous = currentFontStyle; currentFontStyle = FontStyles.Italic; Render(node, box); currentFontStyle = previous; } break; case "u": { var previous = currentUnderline; currentUnderline = true; Render(node, box); currentUnderline = previous; } break; case "strike": { var previous = currentStrike; currentStrike = true; Render(node, box); currentStrike = previous; } break; case "br": FillBuffer(new LineBreak()); break; case "a": { var previous = isHyperlink; isHyperlink = true; Render(node, box); isHyperlink = previous; } break; case "ul": FlushBuffer(box.Blocks); box.Blocks.Add(Render((HTMLUListElement)node)); break; case "ol": FlushBuffer(box.Blocks); box.Blocks.Add(Render((HTMLOListElement)node)); break; case "dl": FlushBuffer(box.Blocks); box.Blocks.Add(Render((HTMLDListElement)node)); break; case "p": FlushBuffer(box.Blocks); Render(node, box); break; case "div": FlushBuffer(box.Blocks); box.Blocks.Add(RenderBox(node)); break; default: Render(node, box); break; } break; } } }
public int GetCellDescent(FontStyle style) { return(GetNativeMetric(Metric.CellDescent, style)); }
public int GetEmHeight(FontStyle style) { return(GetNativeMetric(Metric.EMHeight, style)); }
int IComparable.CompareTo(object obj) { var item = obj as TypefaceListItem; if (item == null) { return(-1); } // Sort all simulated faces after all non-simulated faces. if (_simulated != item._simulated) { return(_simulated ? 1 : -1); } // If weight differs then sort based on weight (lightest first). int difference = FontWeight.ToOpenTypeWeight() - item.FontWeight.ToOpenTypeWeight(); if (difference != 0) { return(difference > 0 ? 1 : -1); } // If style differs then sort based on style (Normal, Italic, then Oblique). FontStyle thisStyle = FontStyle; FontStyle otherStyle = item.FontStyle; if (thisStyle != otherStyle) { if (thisStyle == FontStyles.Normal) { // This item is normal style and should come first. return(-1); } if (otherStyle == FontStyles.Normal) { // The other item is normal style and should come first. return(1); } // Neither is normal so sort italic before oblique. return((thisStyle == FontStyles.Italic) ? -1 : 1); } // If stretch differs then sort based on stretch (Normal first, then numerically). FontStretch thisStretch = FontStretch; FontStretch otherStretch = item.FontStretch; if (thisStretch != otherStretch) { if (thisStretch == FontStretches.Normal) { // This item is normal stretch and should come first. return(-1); } if (otherStretch == FontStretches.Normal) { // The other item is normal stretch and should come first. return(1); } // Neither is normal so sort numerically. return(thisStretch.ToOpenTypeStretch() < otherStretch.ToOpenTypeStretch() ? -1 : 0); } // They're the same. return(0); }
public int GetLineSpacing(FontStyle style) { return(GetNativeMetric(Metric.LineSpacing, style)); }
/// <summary>Generates the HTML text code.</summary> /// <param name="alignment">The alignment.</param> /// <param name="text">The text.</param> /// <param name="prefixCode">The prefix code.</param> /// <param name="fontStyle">The font style.</param> /// <returns>The <see cref="string"/>.</returns> public static string GenerateHTMLTextCode(HorizontalAlign alignment, string text, string prefixCode = "p", FontStyle fontStyle = FontStyle.Regular) { // Allow using custom prefix text to create specific types like: 'h1' or 'p'. // FontStyle style = FontStyle.Bold | FontStyle.Regular; // Add custom font styling. // <p align="center" style="font-style:italic;font-size:12pt"> // <p align="center" style="font-style:italic;"> // Features the latest project repositories as a gallery showcase. // </p> StringBuilder imageBuilder = new StringBuilder(); imageBuilder.AppendLine(string.Format(@"<{1} align={0}{2}{0}>", Constants.Quotes, prefixCode, alignment.ToString())); // Create the font style. // imageBuilder.Append(string.Format(@"style={0}font-style:italic;{0}>", Constants.Quotes, 0)); // imageBuilder.Append(string.Format(@"style={0}{2}{0}>", Constants.Quotes, 0)); imageBuilder.AppendLine($@"{text}"); imageBuilder.AppendLine($@"</{prefixCode}>"); return(imageBuilder.ToString()); }
public static void applyStyleToTextbox(BBCodeStyle style, RichTextBox tf, int selStart, int selEnd) { if (style == null || tf == null || selEnd <= selStart || selEnd < 0) { return; } tf.Select(selStart, selEnd); FontStyle fontStyle = tf.Font.Style; String fontName = tf.Font.Name; float fontSize = tf.Font.Size; if (style.isBold == StateMode.ON) { fontStyle |= FontStyle.Bold; } else if (style.isBold == StateMode.OFF) { fontStyle &= ~FontStyle.Bold; } if (style.isItalic == StateMode.ON) { fontStyle |= FontStyle.Italic; } else if (style.isItalic == StateMode.OFF) { fontStyle &= ~FontStyle.Italic; } if (style.isUnderlined == StateMode.ON) { fontStyle |= FontStyle.Underline; } else if (style.isUnderlined == StateMode.OFF) { fontStyle &= ~FontStyle.Underline; } if (style.isStriked == StateMode.ON) { fontStyle |= FontStyle.Strikeout; } else if (style.isStriked == StateMode.OFF) { fontStyle &= ~FontStyle.Strikeout; } if (style.fontSize > 0) { fontSize = (float)style.fontSize; } else if (style.fontSize < 0) { fontSize += (float)style.fontSize; } if (style.fontName != null && style.fontName.Length > 0) { fontName = style.fontName; } if (style.foreColor != null) { tf.SelectionColor = Color.FromArgb((int)((uint)(0xFF000000) | (uint)(style.foreColor.color & 0xFFFFFF))); } if (style.backColor != null) { tf.SelectionBackColor = Color.FromArgb((int)((uint)(0xFF000000) | (uint)(style.backColor.color & 0xFFFFFF))); } Font font = new Font(fontName, (float)(fontSize > 1.0f ? fontSize : 1.0f), fontStyle); tf.SelectionFont = font; }
private void RenderTextRun(WpfTextTuple textInfo, ref Point ctp, string text, double rotate, WpfTextPlacement placement) { if (string.IsNullOrWhiteSpace(text)) { return; } WpfFontFamilyInfo familyInfo = textInfo.Item1; double emSize = textInfo.Item2; WpfTextStringFormat stringFormat = textInfo.Item3; SvgTextContentElement element = textInfo.Item4; FontFamily fontFamily = familyInfo.Family; FontWeight fontWeight = familyInfo.Weight; FontStyle fontStyle = familyInfo.Style; FontStretch fontStretch = familyInfo.Stretch; WpfSvgPaint fillPaint = new WpfSvgPaint(_context, element, "fill"); Brush textBrush = fillPaint.GetBrush(); WpfSvgPaint strokePaint = new WpfSvgPaint(_context, element, "stroke"); Pen textPen = strokePaint.GetPen(); if (textBrush == null && textPen == null) { return; } if (textBrush == null) { // If here, then the pen is not null, and so the fill cannot be null. // We set this to transparent for stroke only text path... textBrush = Brushes.Transparent; } if (textPen != null) { textPen.LineJoin = PenLineJoin.Miter; // Better for text rendering textPen.MiterLimit = 1; } TextDecorationCollection textDecors = GetTextDecoration(element); if (textDecors == null) { SvgTextElement textElement = element.ParentNode as SvgTextElement; if (textElement != null) { textDecors = GetTextDecoration(textElement); } } TextAlignment alignment = stringFormat.Alignment; bool hasWordSpacing = false; string wordSpaceText = element.GetAttribute("word-spacing"); double wordSpacing = 0; if (!string.IsNullOrWhiteSpace(wordSpaceText) && double.TryParse(wordSpaceText, out wordSpacing) && !wordSpacing.Equals(0)) { hasWordSpacing = true; } bool hasLetterSpacing = false; string letterSpaceText = element.GetAttribute("letter-spacing"); double letterSpacing = 0; if (!string.IsNullOrWhiteSpace(letterSpaceText) && double.TryParse(letterSpaceText, out letterSpacing) && !letterSpacing.Equals(0)) { hasLetterSpacing = true; } bool isRotatePosOnly = false; IList <WpfTextPosition> textPositions = null; int textPosCount = 0; if ((placement != null && placement.HasPositions)) { textPositions = placement.Positions; textPosCount = textPositions.Count; isRotatePosOnly = placement.IsRotateOnly; } WpfTextBuilder textBuilder = WpfTextBuilder.Create(familyInfo, this.TextCulture, emSize); this.IsTextPath = true; if (textPositions != null && textPositions.Count != 0) { if (textPositions.Count == text.Trim().Length) //TODO: Best way to handle this... { text = text.Trim(); } } if (hasLetterSpacing || hasWordSpacing || textPositions != null) { double spacing = Convert.ToDouble(letterSpacing); int startSpaces = 0; for (int i = 0; i < text.Length; i++) { if (char.IsWhiteSpace(text[i])) { startSpaces++; } else { break; } } int j = 0; string inputText = string.Empty; for (int i = 0; i < text.Length; i++) { // Avoid rendering only spaces at the start of text run... if (i == 0 && startSpaces != 0) { inputText = text.Substring(0, startSpaces + 1); i += startSpaces; } else { inputText = new string(text[i], 1); } if (this.IsMeasuring) { var textSize = textBuilder.MeasureText(element, inputText); this.AddTextWidth(ctp, textSize.Width); continue; } textBuilder.Trimming = stringFormat.Trimming; textBuilder.TextAlignment = stringFormat.Alignment; if (textDecors != null && textDecors.Count != 0) { textBuilder.SetTextDecorations(textDecors); } WpfTextPosition?textPosition = null; if (textPositions != null && j < textPosCount) { textPosition = textPositions[j]; } //float xCorrection = 0; //if (alignment == TextAlignment.Left) // xCorrection = emSize * 1f / 6f; //else if (alignment == TextAlignment.Right) // xCorrection = -emSize * 1f / 6f; double yCorrection = textBuilder.Baseline; float rotateAngle = (float)rotate; if (textPosition != null) { if (!isRotatePosOnly) { Point pt = textPosition.Value.Location; ctp.X = pt.X; ctp.Y = pt.Y; } rotateAngle = (float)textPosition.Value.Rotation; } Point textStart = ctp; RotateTransform rotateAt = null; if (!rotateAngle.Equals(0)) { rotateAt = new RotateTransform(rotateAngle, textStart.X, textStart.Y); _drawContext.PushTransform(rotateAt); } Point textPoint = new Point(ctp.X, ctp.Y - yCorrection); Geometry textGeometry = textBuilder.Build(element, inputText, textPoint.X, textPoint.Y); if (textGeometry != null && !textGeometry.IsEmpty()) { _drawContext.DrawGeometry(textBrush, textPen, ExtractTextPathGeometry(textGeometry)); this.IsTextPath = true; } //float bboxWidth = (float)formattedText.Width; double bboxWidth = textGeometry.Bounds.Width; if (alignment == TextAlignment.Center) { bboxWidth /= 2f; } else if (alignment == TextAlignment.Right) { bboxWidth = 0; } //ctp.X += bboxWidth + emSize / 4 + spacing; if (hasLetterSpacing) { ctp.X += bboxWidth + letterSpacing; } if (hasWordSpacing && char.IsWhiteSpace(text[i])) { if (hasLetterSpacing) { ctp.X += wordSpacing; } else { ctp.X += bboxWidth + wordSpacing; } } else { if (!hasLetterSpacing) { ctp.X += bboxWidth; } } if (rotateAt != null) { _drawContext.Pop(); } j++; } } else { if (this.IsMeasuring) { var textSize = textBuilder.MeasureText(element, text); this.AddTextWidth(ctp, textSize.Width); return; } var textContext = this.TextContext; if (textContext != null && textContext.IsPositionChanged(element) == false) { if (alignment == TextAlignment.Center && this.TextWidth > 0) { alignment = TextAlignment.Left; } } textBuilder.TextAlignment = alignment; textBuilder.Trimming = stringFormat.Trimming; if (textDecors != null && textDecors.Count != 0) { textBuilder.SetTextDecorations(textDecors); } //float xCorrection = 0; //if (alignment == TextAlignment.Left) // xCorrection = emSize * 1f / 6f; //else if (alignment == TextAlignment.Right) // xCorrection = -emSize * 1f / 6f; double yCorrection = textBuilder.Baseline; float rotateAngle = (float)rotate; Point textPoint = new Point(ctp.X, ctp.Y - yCorrection); RotateTransform rotateAt = null; if (!rotateAngle.Equals(0)) { rotateAt = new RotateTransform(rotateAngle, ctp.X, ctp.Y); _drawContext.PushTransform(rotateAt); } Geometry textGeometry = textBuilder.Build(element, text, textPoint.X, textPoint.Y); if (textGeometry != null && !textGeometry.IsEmpty()) { _drawContext.DrawGeometry(textBrush, textPen, ExtractTextPathGeometry(textGeometry)); } //float bboxWidth = (float)formattedText.Width; // double bboxWidth = textGeometry.Bounds.Width; double bboxWidth = textBuilder.Width; if (alignment == TextAlignment.Center) { bboxWidth /= 2f; } else if (alignment == TextAlignment.Right) { bboxWidth = 0; } //ctp.X += bboxWidth + emSize / 4; ctp.X += bboxWidth; if (rotateAt != null) { _drawContext.Pop(); } } }
private void Page_Load(object sender, System.EventArgs e) { //Set the content type Response.ContentType = "image/jpeg"; ImageJob job; try { string file = Request.QueryString["file"]; job = new ImageJob(Server.MapPath(file)); // Process the image foreach (string command in Request.QueryString.Keys) { // Tolerance is a vertue. string commandUC = command.ToUpper(); // Parameters container. string values = string.Empty; // Add text if (commandUC.StartsWith("TEXT")) { values = Request.QueryString[command]; string[] prms = values.Split(';'); // We need some explicit conversion here. FontStyle fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), prms[3], true); StringAlignment alignment = (StringAlignment)Enum.Parse(typeof(StringAlignment), prms[8], true);; job.AddText(prms[0], prms[1], Convert.ToInt32(prms[2]), fontStyle, Color.FromName(prms[4]), Convert.ToBoolean(prms[5]), Convert.ToInt32(prms[6]), Convert.ToInt32(prms[7]), alignment); } else if (commandUC.StartsWith("ROTATE")) { values = Request.QueryString[command]; if (values.ToUpper() == "LEFT") { job.RotateLeft(); } else if (values.ToUpper() == "RIGHT") { job.RotateRight(); } else { job.Rotate(float.Parse(values)); } } else if (commandUC.StartsWith("FLIP")) { values = Request.QueryString[command]; if (values.ToUpper().StartsWith("HORI")) { job.Flip(FlipType.Horizontal); } else if (values.ToUpper().StartsWith("VERT")) { job.Flip(FlipType.Vertical); } else if (values.ToUpper().StartsWith("BOTH")) { job.Flip(FlipType.Both); } } else if (commandUC.StartsWith("CROP")) { values = Request.QueryString[command]; Selection selection = new Selection(values.Replace(";", ",")); job.Crop(selection); } else if (commandUC.StartsWith("RESIZE")) { values = Request.QueryString[command]; string[] prms = values.Split(';'); job.ResizeImage(Convert.ToInt32(prms[0]), Convert.ToInt32(prms[1]), Convert.ToBoolean(prms[2]), Convert.ToBoolean(prms[3])); } else if (commandUC.StartsWith("CANVAS")) { values = HttpUtility.UrlDecode(Request.QueryString[command]); string[] prms = values.Split(';'); // We need some explicit conversion here. AnchorType anchor = (AnchorType)Enum.Parse(typeof(AnchorType), prms[2], true); job.ResizeCanvas(Convert.ToInt32(prms[0]), Convert.ToInt32(prms[1]), anchor, System.Drawing.Color.FromName(prms[3])); } else if (commandUC.StartsWith("ZOOM")) { values = Request.QueryString[command]; string[] prms = values.Split(';'); job.Zoom(Convert.ToInt32(prms[0]), Convert.ToInt32(prms[1]), float.Parse(prms[2])); } } // Send the data to the browser job.Save(Response.OutputStream, FileCompression.CCITT3, 70, FileFormat.Jpeg); } catch { Bitmap bitMapImage = new System.Drawing.Bitmap(300, 100, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics graphicImage = Graphics.FromImage(bitMapImage); graphicImage.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.Red); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; graphicImage.DrawString("Invalid parameters!", new Font("Arial", 23, FontStyle.Bold), drawBrush, new Point(150, 30), stringFormat); bitMapImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); graphicImage.Dispose(); bitMapImage.Dispose(); } }
public Font(string family, float size, FontStyle style) { }
public override void RenderSingleLineText(SvgTextContentElement element, ref Point ctp, string text, double rotate, WpfTextPlacement placement) { if (string.IsNullOrWhiteSpace(text)) { return; } double emSize = GetComputedFontSize(element); var fontFamilyInfo = GetTextFontFamilyInfo(element); WpfTextStringFormat stringFormat = GetTextStringFormat(element); if (fontFamilyInfo.WpfFontFamilyType == WpfFontFamilyType.Svg) { WpfTextTuple textInfo = new WpfTextTuple(fontFamilyInfo, emSize, stringFormat, element); this.RenderSingleLineText(textInfo, ref ctp, text, rotate, placement); return; } FontFamily fontFamily = fontFamilyInfo.Family; FontStyle fontStyle = fontFamilyInfo.Style; FontWeight fontWeight = fontFamilyInfo.Weight; FontStretch fontStretch = fontFamilyInfo.Stretch; // Fix the use of Postscript fonts... WpfFontFamilyVisitor fontFamilyVisitor = _context.FontFamilyVisitor; if (!string.IsNullOrWhiteSpace(_actualFontName) && fontFamilyVisitor != null) { WpfFontFamilyInfo familyInfo = fontFamilyVisitor.Visit(_actualFontName, fontFamilyInfo, _context); if (familyInfo != null && !familyInfo.IsEmpty) { fontFamily = familyInfo.Family; fontWeight = familyInfo.Weight; fontStyle = familyInfo.Style; fontStretch = familyInfo.Stretch; } } WpfSvgPaint fillPaint = new WpfSvgPaint(_context, element, "fill"); Brush textBrush = fillPaint.GetBrush(); WpfSvgPaint strokePaint = new WpfSvgPaint(_context, element, "stroke"); Pen textPen = strokePaint.GetPen(); if (textBrush == null && textPen == null) { return; } if (textBrush == null) { // If here, then the pen is not null, and so the fill cannot be null. // We set this to transparent for stroke only text path... textBrush = Brushes.Transparent; } if (textPen != null) { textPen.LineJoin = PenLineJoin.Round; // Better for text rendering } TextDecorationCollection textDecors = GetTextDecoration(element); TextAlignment alignment = stringFormat.Alignment; bool hasWordSpacing = false; string wordSpaceText = element.GetAttribute("word-spacing"); double wordSpacing = 0; if (!string.IsNullOrWhiteSpace(wordSpaceText) && double.TryParse(wordSpaceText, out wordSpacing) && !wordSpacing.Equals(0)) { hasWordSpacing = true; } bool hasLetterSpacing = false; string letterSpaceText = element.GetAttribute("letter-spacing"); double letterSpacing = 0; if (!string.IsNullOrWhiteSpace(letterSpaceText) && double.TryParse(letterSpaceText, out letterSpacing) && !letterSpacing.Equals(0)) { hasLetterSpacing = true; } bool isRotatePosOnly = false; IList <WpfTextPosition> textPositions = null; int textPosCount = 0; if ((placement != null && placement.HasPositions)) { textPositions = placement.Positions; textPosCount = textPositions.Count; isRotatePosOnly = placement.IsRotateOnly; } var typeFace = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch); if (hasLetterSpacing || hasWordSpacing || textPositions != null) { for (int i = 0; i < text.Length; i++) { var nextText = new string(text[i], 1); FormattedText formattedText = new FormattedText(nextText, _context.CultureInfo, stringFormat.Direction, typeFace, emSize, textBrush); formattedText.TextAlignment = stringFormat.Alignment; formattedText.Trimming = stringFormat.Trimming; if (textDecors != null && textDecors.Count != 0) { formattedText.SetTextDecorations(textDecors); } WpfTextPosition?textPosition = null; if (textPositions != null && i < textPosCount) { textPosition = textPositions[i]; } //float xCorrection = 0; //if (alignment == TextAlignment.Left) // xCorrection = emSize * 1f / 6f; //else if (alignment == TextAlignment.Right) // xCorrection = -emSize * 1f / 6f; double yCorrection = formattedText.Baseline; float rotateAngle = (float)rotate; if (textPosition != null) { if (!isRotatePosOnly) { Point pt = textPosition.Value.Location; ctp.X = pt.X; ctp.Y = pt.Y; } rotateAngle = (float)textPosition.Value.Rotation; } Point textStart = ctp; RotateTransform rotateAt = null; if (!rotateAngle.Equals(0)) { rotateAt = new RotateTransform(rotateAngle, textStart.X, textStart.Y); _drawContext.PushTransform(rotateAt); } Point textPoint = new Point(textStart.X, textStart.Y - yCorrection); if (textPen != null || _context.TextAsGeometry) { Geometry textGeometry = formattedText.BuildGeometry(textPoint); if (textGeometry != null && !textGeometry.IsEmpty()) { _drawContext.DrawGeometry(textBrush, textPen, ExtractTextPathGeometry(textGeometry)); this.IsTextPath = true; } else { _drawContext.DrawText(formattedText, textPoint); } } else { _drawContext.DrawText(formattedText, textPoint); } //float bboxWidth = (float)formattedText.Width; double bboxWidth = formattedText.WidthIncludingTrailingWhitespace; if (alignment == TextAlignment.Center) { bboxWidth /= 2f; } else if (alignment == TextAlignment.Right) { bboxWidth = 0; } //ctp.X += bboxWidth + emSize / 4 + spacing; if (hasLetterSpacing) { ctp.X += bboxWidth + letterSpacing; } if (hasWordSpacing && char.IsWhiteSpace(text[i])) { if (hasLetterSpacing) { ctp.X += wordSpacing; } else { ctp.X += bboxWidth + wordSpacing; } } else { if (!hasLetterSpacing) { ctp.X += bboxWidth; } } if (rotateAt != null) { _drawContext.Pop(); } } } else { FormattedText formattedText = new FormattedText(text, _context.CultureInfo, stringFormat.Direction, typeFace, emSize, textBrush); formattedText.TextAlignment = stringFormat.Alignment; formattedText.Trimming = stringFormat.Trimming; if (textDecors != null && textDecors.Count != 0) { formattedText.SetTextDecorations(textDecors); } //float xCorrection = 0; //if (alignment == TextAlignment.Left) // xCorrection = emSize * 1f / 6f; //else if (alignment == TextAlignment.Right) // xCorrection = -emSize * 1f / 6f; double yCorrection = formattedText.Baseline; float rotateAngle = (float)rotate; Point textPoint = new Point(ctp.X, ctp.Y - yCorrection); RotateTransform rotateAt = null; if (!rotateAngle.Equals(0)) { rotateAt = new RotateTransform(rotateAngle, ctp.X, ctp.Y); _drawContext.PushTransform(rotateAt); } if (textPen != null || _context.TextAsGeometry) { Geometry textGeometry = formattedText.BuildGeometry(textPoint); if (textGeometry != null && !textGeometry.IsEmpty()) { _drawContext.DrawGeometry(textBrush, textPen, ExtractTextPathGeometry(textGeometry)); this.IsTextPath = true; } else { _drawContext.DrawText(formattedText, textPoint); } } else { _drawContext.DrawText(formattedText, textPoint); } //float bboxWidth = (float)formattedText.Width; double bboxWidth = formattedText.WidthIncludingTrailingWhitespace; if (alignment == TextAlignment.Center) { bboxWidth /= 2f; } else if (alignment == TextAlignment.Right) { bboxWidth = 0; } //ctp.X += bboxWidth + emSize / 4; ctp.X += bboxWidth; if (rotateAt != null) { _drawContext.Pop(); } } }
public MathListBuilder(string str) { _chars = str.ToCharArray(); _currentFontStyle = FontStyle.Default; _length = str.Length; }
internal IMathList BuildInternal(bool oneCharOnly, char stopChar) { if (oneCharOnly && stopChar > 0) { throw new InvalidOperationException("Cannot set both oneCharOnly and stopChar"); } var r = new MathList(); IMathAtom prevAtom = null; while (HasCharacters) { if (_error != null) { return(null); } IMathAtom atom; var ch = GetNextCharacter(); if (oneCharOnly) { if (ch == '^' || ch == '}' || ch == '_' || ch == '&') { // this is not the character we are looking for. They are for the caller to look at. UnlookCharacter(); return(r); } } if (stopChar > 0 && ch == stopChar) { return(r); } switch (ch) { case '^': if (prevAtom == null || prevAtom.Superscript != null || !prevAtom.ScriptsAllowed) { prevAtom = MathAtoms.Create(MathAtomType.Ordinary, string.Empty); r.Add(prevAtom); } // this is a superscript for the previous atom. // note, if the next char is StopChar, it will be consumed and doesn't count as stop. prevAtom.Superscript = this.BuildInternal(true); continue; case '_': if (prevAtom == null || prevAtom.Subscript != null || !prevAtom.ScriptsAllowed) { prevAtom = MathAtoms.Create(MathAtomType.Ordinary, string.Empty); r.Add(prevAtom); } // this is a subscript for the previous atom. // note, if the next char is StopChar, it will be consumed and doesn't count as stop. prevAtom.Subscript = this.BuildInternal(true); continue; case '{': IMathList sublist; if (_currentEnvironment != null && _currentEnvironment.Name == null) { // \\ or \cr which do not have a corrosponding \end var oldEnv = _currentEnvironment; _currentEnvironment = null; sublist = BuildInternal(false, '}'); _currentEnvironment = oldEnv; } else { sublist = BuildInternal(false, '}'); } if (sublist == null) { return(null); } prevAtom = sublist.Atoms.LastOrDefault(); if (oneCharOnly) { r.Append(sublist); return(r); } #warning TODO Example //https://phabricator.wikimedia.org/T99369 //https://phab.wmfusercontent.org/file/data/xsimlcnvo42siudvwuzk/PHID-FILE-bdcqexocj5b57tj2oezn/math_rendering.png //dt, \text{d}t, \partial t, \nabla\psi \\ \underline\overline{dy/dx, \text{d}y/\text{d}x, \frac{dy}{dx}, \frac{\text{d}y}{\text{d}x}, \frac{\partial^2}{\partial x_1\partial x_2}y} \\ \prime, atom = new Group { InnerList = sublist }; break; case '}': if (oneCharOnly || stopChar != 0) { throw new InvalidCodePathException("This should have been handled before."); } SetError("Missing opening brace"); return(null); case '\\': var command = ReadCommand(); var done = StopCommand(command, r, stopChar); if (done != null) { return(done); } if (_error != null) { return(null); } if (ApplyModifier(command, prevAtom)) { continue; } var fontStyleQ = MathAtoms.FontStyle(command); if (fontStyleQ.HasValue) { var fontStyle = fontStyleQ.Value; var oldSpacesAllowed = _textMode; var oldFontStyle = _currentFontStyle; _textMode = (command == "text"); _currentFontStyle = fontStyle; var childList = BuildInternal(true); if (childList == null) { return(null); } _currentFontStyle = oldFontStyle; _textMode = oldSpacesAllowed; prevAtom = childList.Atoms.LastOrDefault(); r.Append(childList); if (oneCharOnly) { return(r); } continue; } atom = AtomForCommand(command, stopChar); if (atom == null) { SetError(_error ?? "Internal error"); return(null); } break; case '&': { // column separation in tables if (_currentEnvironment != null) { return(r); } var table = BuildTable(null, r, false, stopChar); if (table == null) { return(null); } return(MathLists.WithAtoms(table)); } case '\'': // this case is NOT in iosMath int i = 1; while (ExpectCharacter('\'')) { i++; } atom = new Prime(i); break; default: if (_textMode && ch == ' ') { atom = MathAtoms.ForLatexSymbolName(" "); } else { atom = MathAtoms.ForCharacter(ch); if (atom == null) { // not a recognized character continue; } } break; } if (atom == null) { throw new InvalidCodePathException("Atom shouldn't be null"); } atom.FontStyle = _currentFontStyle; r.Add(atom); prevAtom = atom; if (oneCharOnly) { return(r); // we consumed our character. } } if (stopChar > 0) { if (stopChar == '}') { SetError("Missing closing brace"); } else { // we never found our stop character. SetError("Expected character not found: " + stopChar.ToString()); } } return(r); }
public void Ctor_FamilyName_Size_Style_Unit(FontFamily fontFamily, float emSize, FontStyle style, GraphicsUnit unit) { try { using (var font = new Font(fontFamily.Name, emSize, style, unit)) { VerifyFont(font, fontFamily.Name, emSize, style, unit, 1, false); } } finally { fontFamily.Dispose(); } }
public void Ctor_FamilyName_Size_Style_Unit_GdiCharSet_GdiVerticalFont(FontFamily fontFamily, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont) { try { using (var font = new Font(fontFamily.Name, emSize, style, unit, gdiCharSet, gdiVerticalFont)) { VerifyFont(font, fontFamily.Name, emSize, style, unit, gdiCharSet, gdiVerticalFont); } } finally { fontFamily.Dispose(); } }
public void AddText(string name, string text, Vector2 pos, Vector2 sz, Font font, int fontSize = 13, FontStyle style = FontStyle.Normal, TextAnchor alignment = TextAnchor.UpperLeft) { CanvasText t = new CanvasText(canvas, position + pos, sz, font, text, fontSize, style, alignment); texts.Add(name, t); }
private static void VerifyFont(Font font, string expectedName, float expectedEmSize, FontStyle expectedStyle, GraphicsUnit expectedUnit, byte expectedGdiCharset, bool expectedGdiVerticalFont) { Assert.Equal(expectedName, font.Name); Assert.Equal(expectedEmSize, font.Size); Assert.Equal(expectedStyle, font.Style); Assert.Equal((expectedStyle & FontStyle.Bold) != 0, font.Bold); Assert.Equal((expectedStyle & FontStyle.Italic) != 0, font.Italic); Assert.Equal((expectedStyle & FontStyle.Strikeout) != 0, font.Strikeout); Assert.Equal((expectedStyle & FontStyle.Underline) != 0, font.Underline); Assert.Equal(expectedUnit, font.Unit); Assert.Equal(expectedGdiCharset, font.GdiCharSet); Assert.Equal(expectedGdiVerticalFont, font.GdiVerticalFont); Assert.False(font.IsSystemFont); Assert.Empty(font.SystemFontName); }
public static ReportFont Create(FontList fontList, float fontSize, ReportColor color, FontStyle style) { return(new ReportFont { FontList = fontList, Color = color, FontSize = fontSize, Style = style }); }
public static void Text(Text text, string txt, int size, Color color, TextAnchor anchor, bool richText, bool hOverFlow, bool vOverFlow, bool rayCast, FontStyle style = FontStyle.Normal) { text.text = txt; text.fontSize = size; text.color = color; text.alignment = anchor; text.raycastTarget = rayCast; text.supportRichText = richText; text.horizontalOverflow = hOverFlow ? HorizontalWrapMode.Overflow : HorizontalWrapMode.Wrap; text.verticalOverflow = vOverFlow ? VerticalWrapMode.Overflow : VerticalWrapMode.Truncate; text.fontStyle = style; }
private void RepaintSingleCell(Point cellpos) { if (m_DontRepaint) { return; } if (cellpos.X < 0 || cellpos.Y < 0 || cellpos.Y >= CellRows.Count || cellpos.X >= CellRows[0].Count) { return; } /* int max_x = cellpos.X + 1; * int max_y = cellpos.Y + 1; * for (cellpos.X--; cellpos.X < max_x; cellpos.X++) * { * for (cellpos.Y--; cellpos.Y < max_y; cellpos.Y++) * { * if (cellpos.Y < 0 || cellpos.X < 0) * continue; */ CellInfo ci = CellRows[cellpos.Y][cellpos.X]; //m_PaintBuffer.FillRectangle(new SolidBrush(this.BackColor), cellpos.X * m_CellWidth, cellpos.Y * m_CellHeight, m_CellWidth, m_CellHeight); m_PaintBuffer.FillRectangle(this.Colors.SolidBrushes[ci.BackColor], cellpos.X * m_CellWidth, cellpos.Y * m_CellHeight, m_CellWidth, m_CellHeight); if (CellRows[cellpos.Y][cellpos.X].Character != ' ') { FontStyle styles = new FontStyle(); if (ci.Bold) { styles |= FontStyle.Bold; } if (ci.Underlined) { styles |= FontStyle.Underline; } Font font = new Font(this.Font, styles); m_PaintBuffer.DrawString(ci.Character.ToString(), font, this.Colors.SolidBrushes[ci.ForeColor], cellpos.X * m_CellWidth, cellpos.Y * m_CellHeight); } m_PaintBuffer.DrawLine(m_SeperatorPen, cellpos.X * m_CellWidth, (1 + cellpos.Y) * m_CellHeight, (1 + cellpos.X) * m_CellWidth, (1 + cellpos.Y) * m_CellHeight); m_PaintBuffer.DrawLine(m_SeperatorPen, (1 + cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight, (1 + cellpos.X) * m_CellWidth, (1 + cellpos.Y) * m_CellHeight); m_PaintBuffer.DrawLine(m_SeperatorPen, (cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight, (1 + cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight); m_PaintBuffer.DrawLine(m_SeperatorPen, (cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight, (cellpos.X) * m_CellWidth, (1 + cellpos.Y) * m_CellHeight); if (m_SelectedCellPosition.X == cellpos.X && m_SelectedCellPosition.Y == cellpos.Y) { m_PaintBuffer.DrawRectangle(m_HighlightPen, 1 + (m_SelectedCellPosition.X * (m_CellWidth + (m_SeperatorWidth / 2))), 1 + (m_SelectedCellPosition.Y * (m_CellHeight + (m_SeperatorWidth / 2))), m_CellWidth - 2, m_CellHeight - 2); } // } //} int xpos = (cellpos.X * m_CellWidth) - 5; int ypos = (cellpos.Y * m_CellHeight) - 5; if (xpos < 0) { xpos = 0; } if (ypos < 0) { ypos = 0; } this.Invalidate(new Rectangle(new Point(xpos, ypos), new Size(m_CellWidth + 5, m_CellHeight + 5))); }
public Text(Entry start, Entry end, string text, float fontSize, string fontFamily, FontStyle fontStyle, Color color) : base(color) { this.Start = start; this.String = text; this.Size = fontSize; this.Font = fontFamily; this.Style = fontStyle; this.End = end; }
public MobileLabel CreateLabel(string text, int left, int top, int width, int height, MobileFontSize size, MobileFontPosition position, MobileFontColors color, FontStyle fontStyle, string controlName) { MobileLabel NewControl = new MobileLabel(MainForm, text, left, top, width, height, size, position, color, fontStyle, controlName); ControlsArray.Add(NewControl); return(NewControl); }
/// <summary> /// Adds a new syntax coloring item to this CodeBox /// </summary> public void AddSyntax(string regex, Color color, FontStyle style = FontStyle.Regular) { SyntaxColors.Add(Tuple.Create(new Regex(regex), new TextStyle(new SolidBrush(color), bg, style))); }
public MobileLabel CreateLabel(string text, int left, int top, int width, MobileFontSize size, MobileFontPosition position, MobileFontColors color, FontStyle fontStyle, string controlName) { return(CreateLabel(text, left, top, width, 0, size, position, color, fontStyle, controlName)); }
public static GUIStyle CreateStyle(TextAnchor anchor, FontStyle style, int fontSize, bool wordWrap, Color color) { return(CreateStyle(anchor, style, fontSize, wordWrap, new Color[6].Select(x => color).ToArray())); }