/// <summary> /// Set the specified style. /// </summary> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public override void SetStyle(StyleText styleText, Style style) { if (Number != null) { styleText.ApplyTo(Number.gameObject); } }
/// <summary> /// Set the style. /// </summary> /// <param name="styleBackground">Style for the background.</param> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public virtual void SetStyle(StyleImage styleBackground, StyleText styleText, Style style) { styleBackground.ApplyTo(Background); if ((Owner != null) && (Owner.IsTable)) { Background.sprite = null; if (GraphicsBackground != null) { GraphicsBackground.ForEach(style.Table.Background.ApplyTo); } } if (GraphicsForeground != null) { foreach (var gf in GraphicsForeground) { if (gf != null) { styleText.ApplyTo(gf.gameObject); } } } ResetGraphics(); }
protected override void OnStyleText(StyleText text) { if (FlagNotSet(Flag.RemoveStyles)) { base.OnStyleText(text); } }
/// <summary> /// Set the style. /// </summary> /// <param name="styleBackground">Style for the background.</param> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public override void SetStyle(StyleImage styleBackground, StyleText styleText, Style style) { base.SetStyle(styleBackground, styleText, style); if (Name != null) { styleText.ApplyTo(Name.gameObject); } }
protected override void OnStyleText(StyleText text) { if (text == null || _scriptDepth > 0) { return; } Emit(text.ToString()); base.OnStyleText(text); }
private void draw_file_data(SpriteBatch sprite_batch, Vector2 offset) { sprite_batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); // Team leader // Background FileBg.draw(sprite_batch, offset); // Labels FileLabel.draw(sprite_batch, offset); // Data FileNumber.draw(sprite_batch, offset); DifficultyText.draw(sprite_batch, offset); StyleText.draw(sprite_batch, offset); sprite_batch.End(); }
/// <summary> /// Set the style. /// </summary> /// <param name="styleBackground">Style for the background.</param> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public virtual void SetStyle(StyleImage styleBackground, StyleText styleText, Style style) { styleBackground.ApplyTo(Background); foreach (var gf in GraphicsForeground) { if (gf != null) { styleText.ApplyTo(gf.gameObject); } } var connector = GetComponent <MultipleConnector>(); connector.color = style.Collections.DefaultColor; }
/// <summary> /// Apply style for the specified InputField. /// </summary> /// <param name="style">Style.</param> /// <param name="component">InputField.</param> /// <returns><c>true</c>, if style was set for children gameobjects, <c>false</c> otherwise.</returns> public static bool ApplyTo(StyleText style, TMP_InputField component) { if (component == null) { return(false); } ApplyTo(style, component.textComponent, true); if (component.placeholder != null) { ApplyTo(style, component.placeholder.GetComponent <TextMeshProUGUI>(), true); } return(true); }
/// <summary> /// Apply style for the specified gameobject. /// </summary> /// <param name="style">Style.</param> /// <param name="go">Gameobject.</param> /// <returns><c>true</c>, if style was set for children gameobjects, <c>false</c> otherwise.</returns> public static bool ApplyTo(StyleText style, GameObject go) { var applied = false; if (go != null) { #if UNITY_5_2 || UNITY_5_3 || UNITY_5_3_OR_NEWER applied |= ApplyTo(style, go.GetComponent <TMP_InputField>()); applied |= ApplyTo(style, go.GetComponent <TMP_Text>()); #else applied |= ApplyTo(style, go.GetComponent <TextMeshProUGUI>()); #endif } return(applied); }
public void Parse() { CssParser parser = new CssParser(_css); OnDocumentBegin(); while (true) { StyleElement element = parser.Next(); if (element == null) { OnDocumentEnd(); return; } StyleText styleText = element as StyleText; if (styleText != null) { OnStyleText(styleText); } StyleLiteral styleLiteral = element as StyleLiteral; if (styleLiteral != null) { OnStyleLiteral(styleLiteral); } StyleUrl styleUrl = element as StyleUrl; if (styleUrl != null) { OnStyleUrl(styleUrl); } StyleImport styleImport = element as StyleImport; if (styleImport != null) { OnStyleImport(styleImport); } StyleComment styleComment = element as StyleComment; if (styleComment != null) { OnStyleComment(styleComment); } } }
/// <summary> /// Set the style. /// </summary> /// <param name="styleBackground">Style for the background.</param> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public override void SetStyle(StyleImage styleBackground, StyleText styleText, Style style) { base.SetStyle(styleBackground, styleText, style); PaddingPerLevel = style.TreeView.PaddingPerLevel; style.TreeView.Toggle.ApplyTo(ToggleImage); OnNodeExpand = style.TreeView.OnNodeExpand; AnimateArrow = style.TreeView.AnimateArrow; NodeOpened = style.TreeView.NodeOpened; NodeClosed = style.TreeView.NodeClosed; styleText.ApplyTo(Text); }
protected override void OnStyleText(StyleText text) { }
/// <summary> /// Merges objects from the given scene for the given zoom level. /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <param name="idx"></param> private void MergeObjects(Scene2D target, Scene2D source, int idx) { var lines = new Dictionary <Scene2D.ScenePoints, Scene2DStylesSet>(); var linesIndex = new QuadTree <PointF2D, Scene2D.ScenePoints>(); var polygons = new Dictionary <Scene2D.ScenePoints, Scene2DStylesSet>(); //var polygonsIndex = new QuadTree<PointF2D, Scene2D.ScenePoints>(); Dictionary <uint, SceneObject> sceneObjects = source.GetSceneObjectsAt(idx); float zoomFactor = source.GetMaximumZoomFactorAt(idx); float epsilon = source.CalculateSimplificationEpsilon(zoomFactor); foreach (var sceneObject in sceneObjects) { if (sceneObject.Value.Enum == SceneObjectType.LineObject) { // the scene object is a line object. var sceneLineObject = sceneObject.Value as SceneLineObject; Scene2D.ScenePoints scenePoints = source.GetPoints(sceneLineObject.GeoId); Scene2DStylesSet stylesSet = null; if (!lines.TryGetValue(scenePoints, out stylesSet)) { // create styles set. stylesSet = new Scene2DStylesSet(); lines.Add(scenePoints, stylesSet); // add scenePoints to the index. linesIndex.Add(new PointF2D(scenePoints.X[0], scenePoints.Y[0]), scenePoints); linesIndex.Add(new PointF2D(scenePoints.X[scenePoints.X.Length - 1], scenePoints.Y[scenePoints.Y.Length - 1]), scenePoints); } stylesSet.AddStyleLine(sceneLineObject.StyleId); } else if (sceneObject.Value.Enum == SceneObjectType.LineTextObject) { var sceneLineTextObject = sceneObject.Value as SceneLineTextObject; Scene2D.ScenePoints scenePoints = source.GetPoints(sceneLineTextObject.GeoId); Scene2DStylesSet stylesSet = null; if (!lines.TryGetValue(scenePoints, out stylesSet)) { // create styles set. stylesSet = new Scene2DStylesSet(); lines.Add(scenePoints, stylesSet); // add scenePoints to the index. linesIndex.Add(new PointF2D(scenePoints.X[0], scenePoints.Y[0]), scenePoints); linesIndex.Add(new PointF2D(scenePoints.X[scenePoints.X.Length - 1], scenePoints.Y[scenePoints.Y.Length - 1]), scenePoints); } stylesSet.AddStyleLineText(sceneLineTextObject.StyleId, sceneLineTextObject.TextId); } else if (sceneObject.Value.Enum == SceneObjectType.IconObject) { throw new NotSupportedException("Icons not yet supported!"); //var sceneIconObject = (sceneObject.Value as SceneIconObject); //Scene2D.ScenePoint scenePoint = source.GetPoint(sceneIconObject.GeoId); //source.GetStyleIcon( //target.AddIcon(target.AddPoint(scenePoint.X, scenePoint.Y); } else if (sceneObject.Value.Enum == SceneObjectType.PointObject) { var scenePointObject = (sceneObject.Value as ScenePointObject); Scene2D.ScenePoint scenePoint = source.GetPoint(scenePointObject.GeoId); StylePoint stylePoint = source.GetStylePoint(scenePointObject.StyleId); target.AddStylePoint(target.AddPoint(scenePoint.X, scenePoint.Y), stylePoint.Layer, stylePoint.MinZoom, stylePoint.MaxZoom, stylePoint.Color, stylePoint.Size); } else if (sceneObject.Value.Enum == SceneObjectType.PolygonObject) { // the scene object is a polygon. var scenePolygonObject = (sceneObject.Value as ScenePolygonObject); Scene2D.ScenePoints scenePoints = source.GetPoints(sceneObject.Value.GeoId); Scene2DStylesSet stylesSet = null; if (!polygons.TryGetValue(scenePoints, out stylesSet)) { // create styles set. stylesSet = new Scene2DStylesSet(); polygons.Add(scenePoints, stylesSet); //// add scenePoints to the index. //polygonsIndex.Add(new PointF2D(scenePoints.X[0], scenePoints.Y[0]), scenePoints); //polygonsIndex.Add(new PointF2D(scenePoints.X[scenePoints.X.Length - 1], scenePoints.Y[scenePoints.Y.Length - 1]), scenePoints); } stylesSet.AddStylePolygon(scenePolygonObject.StyleId); //var scenePolygonObject = (sceneObject.Value as ScenePolygonObject); //Scene2D.ScenePoints scenePoints = source.GetPoints(sceneObject.Value.GeoId); //StylePolygon stylePolygon = source.GetStylePolygon(sceneObject.Value.StyleId); //uint? pointsId = target.AddPoints(scenePoints.X, scenePoints.Y); //if (pointsId.HasValue) //{ // target.AddStylePolygon(pointsId.Value, stylePolygon.Layer, stylePolygon.MinZoom, stylePolygon.MaxZoom, // stylePolygon.Color, stylePolygon.Width, stylePolygon.Fill); //} } else if (sceneObject.Value.Enum == SceneObjectType.TextObject) { var sceneTextObject = (sceneObject.Value as SceneTextObject); Scene2D.ScenePoint scenePoint = source.GetPoint(sceneObject.Value.GeoId); StyleText styleText = source.GetStyleText(sceneTextObject.StyleId); string text = source.GetText(sceneTextObject.TextId); target.AddText(target.AddPoint(scenePoint.X, scenePoint.Y), styleText.Layer, styleText.MinZoom, styleText.MaxZoom, styleText.Size, text, styleText.Color, styleText.HaloColor, styleText.HaloRadius, styleText.Font); } } // loop until there are no more candidates. int totalLines = lines.Count; float latestProgress = 0; while (lines.Count > 0) { var line = lines.First(); lines.Remove(line.Key); // report progress. float progress = (float)System.Math.Round((((double)(totalLines - lines.Count) / (double)totalLines) * 100)); if (progress != latestProgress) { OsmSharp.Logging.Log.TraceEvent("SceneSerializer", OsmSharp.Logging.TraceEventType.Information, "Merging lines @z{3}e{4} ({1}/{2})... {0}%", progress, totalLines - lines.Count, totalLines, zoomFactor, epsilon); latestProgress = progress; } // copy the coordinates to lists. double[] x = line.Key.X.Clone() as double[]; double[] y = line.Key.Y.Clone() as double[]; // find a matching line. int mergeCount = 1; Scene2D.ScenePoints found; MatchPosition foundPosition = this.FindMatch(linesIndex, lines, x, y, line.Value, epsilon, out found); while (found != null) { // TODO: keep expanding and duplicating until not possible anymore. // remove the found line. lines.Remove(found); // report progress. progress = (float)System.Math.Round((((double)(totalLines - lines.Count) / (double)totalLines) * 100)); if (progress != latestProgress) { OsmSharp.Logging.Log.TraceEvent("SceneSerializer", OsmSharp.Logging.TraceEventType.Information, "Merging lines @z{3}e{4} ({1}/{2})... {0}%", progress, totalLines - lines.Count, totalLines, zoomFactor, epsilon); latestProgress = progress; } // add the line. int lengthBefore = x.Length; Array.Resize(ref x, x.Length + found.X.Length - 1); Array.Resize(ref y, y.Length + found.Y.Length - 1); switch (foundPosition) { case MatchPosition.FirstFirst: found.X.InsertToReverse(1, x, 0, found.X.Length - 1); found.Y.InsertToReverse(1, y, 0, found.Y.Length - 1); break; case MatchPosition.FirstLast: found.X.InsertTo(0, x, 0, found.X.Length - 1); found.Y.InsertTo(0, y, 0, found.Y.Length - 1); break; case MatchPosition.LastFirst: found.X.CopyTo(x, lengthBefore - 1); found.Y.CopyTo(y, lengthBefore - 1); break; case MatchPosition.LastLast: found.X.CopyToReverse(x, lengthBefore - 1); found.Y.CopyToReverse(y, lengthBefore - 1); break; } // select a new line. foundPosition = this.FindMatch(linesIndex, lines, x, y, line.Value, epsilon, out found); mergeCount++; } // simplify first. double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y }, epsilon); // add the new points. uint?pointsId = target.AddPoints(simplified[0], simplified[1]); // add points again with appropriate styles. if (pointsId.HasValue) { foreach (var style in line.Value) { var scene2DStyleLine = (style as Scene2DStyleLine); if (scene2DStyleLine != null) { StyleLine styleLine = source.GetStyleLine(scene2DStyleLine.StyleLineId); target.AddStyleLine(pointsId.Value, styleLine.Layer, styleLine.MinZoom, styleLine.MaxZoom, styleLine.Color, styleLine.Width, styleLine.LineJoin, styleLine.Dashes); continue; } var scene2DStyleLineText = (style as Scene2DStyleLineText); if (scene2DStyleLineText != null) { StyleText styleText = source.GetStyleLineText(scene2DStyleLineText.StyleLineTextId); string text = source.GetText(scene2DStyleLineText.TextId); target.AddStyleLineText(pointsId.Value, styleText.Layer, styleText.MinZoom, styleText.MaxZoom, styleText.Color, styleText.Size, text, styleText.Font, styleText.HaloColor, styleText.HaloRadius); continue; } } } } // loop until there are no more candidates. totalLines = polygons.Count; latestProgress = 0; while (polygons.Count > 0) { var polygon = polygons.First(); polygons.Remove(polygon.Key); // report progress. float progress = (float)System.Math.Round((((double)(totalLines - polygons.Count) / (double)totalLines) * 100)); if (progress != latestProgress) { OsmSharp.Logging.Log.TraceEvent("SceneSerializer", OsmSharp.Logging.TraceEventType.Information, "Merging polygons @z{3}e{4} ({1}/{2})... {0}%", progress, totalLines - polygons.Count, totalLines, zoomFactor, epsilon); latestProgress = progress; } // copy the coordinates to lists. double[] x = polygon.Key.X.Clone() as double[]; double[] y = polygon.Key.Y.Clone() as double[]; //// find a matching line. //int mergeCount = 1; //Scene2D.ScenePoints found; //MatchPosition foundPosition = this.FindMatch(linesIndex, lines, x, y, line.Value, epsilon, out found); //while (found != null) //{ // TODO: keep expanding and duplicating until not possible anymore. // // remove the found line. // lines.Remove(found); // // report progress. // progress = (float)System.Math.Round((((double)(totalLines - lines.Count) / (double)totalLines) * 100)); // if (progress != latestProgress) // { // OsmSharp.Logging.Log.TraceEvent("SceneSerializer", OsmSharp.Logging.TraceEventType.Information, // "Merging lines @z{3}e{4} ({1}/{2})... {0}%", progress, totalLines - lines.Count, totalLines, zoomFactor, epsilon); // latestProgress = progress; // } // // add the line. // int lengthBefore = x.Length; // Array.Resize(ref x, x.Length + found.X.Length - 1); // Array.Resize(ref y, y.Length + found.Y.Length - 1); // switch (foundPosition) // { // case MatchPosition.FirstFirst: // found.X.InsertToReverse(1, x, 0, found.X.Length - 1); // found.Y.InsertToReverse(1, y, 0, found.Y.Length - 1); // break; // case MatchPosition.FirstLast: // found.X.InsertTo(0, x, 0, found.X.Length - 1); // found.Y.InsertTo(0, y, 0, found.Y.Length - 1); // break; // case MatchPosition.LastFirst: // found.X.CopyTo(x, lengthBefore - 1); // found.Y.CopyTo(y, lengthBefore - 1); // break; // case MatchPosition.LastLast: // found.X.CopyToReverse(x, lengthBefore - 1); // found.Y.CopyToReverse(y, lengthBefore - 1); // break; // } // // select a new line. // foundPosition = this.FindMatch(linesIndex, lines, x, y, line.Value, epsilon, out found); // mergeCount++; //} // simplify first. double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y }, epsilon); // add the new points. uint?pointsId = target.AddPoints(simplified[0], simplified[1]); // add points again with appropriate styles. if (pointsId.HasValue) { foreach (var style in polygon.Value) { var scene2DStylePolygon = (style as Scene2DStylePolygon); if (scene2DStylePolygon != null) { StylePolygon stylePolygon = source.GetStylePolygon(scene2DStylePolygon.StylePolygonId); target.AddStylePolygon(pointsId.Value, stylePolygon.Layer, stylePolygon.MinZoom, stylePolygon.MaxZoom, stylePolygon.Color, stylePolygon.Width, stylePolygon.Fill); continue; } } } } }
/// <summary> /// Deserializes the given leaf. /// </summary> /// <param name="typeModel"></param> /// <param name="data"></param> /// <param name="boxes"></param> /// <returns></returns> protected override List <Primitive2D> DeSerialize(RuntimeTypeModel typeModel, byte[] data, out List <BoxF2D> boxes) { if (_compressed) { // decompress if needed. data = GZipStream.UncompressBuffer(data); } List <Primitive2D> dataLists = new List <Primitive2D>(); boxes = new List <BoxF2D>(); int scaleFactor = _scaleFactor; // Assume the following stuff already exists in the current scene: // - ZoomRanges // - Styles // deserialize the leaf data. SceneObjectBlock leafData = typeModel.Deserialize( new MemoryStream(data), null, typeof(SceneObjectBlock)) as SceneObjectBlock; // decode for (int idx = 0; idx < leafData.PointsX.Count; idx++) { leafData.PointsX[idx] = leafData.PointsX[idx] + leafData.PointsXMin; leafData.PointsY[idx] = leafData.PointsY[idx] + leafData.PointsYMin; } // store the next points. bool[] pointsStarts = new bool[leafData.PointsX.Count]; // loop over all points. for (int idx = 0; idx < leafData.PointPointId.Count; idx++) { pointsStarts[leafData.PointPointId[idx]] = true; } // loop over all text-points. for (int idx = 0; idx < leafData.TextPointPointId.Count; idx++) { pointsStarts[leafData.TextPointPointId[idx]] = true; } // loop over all icons. for (int idx = 0; idx < leafData.IconPointId.Count; idx++) { pointsStarts[leafData.IconPointId[idx]] = true; } // loop over all lines. for (int idx = 0; idx < leafData.LinePointsId.Count; idx++) { pointsStarts[leafData.LinePointsId[idx]] = true; } // loop over all polygons. for (int idx = 0; idx < leafData.PolygonPointsId.Count; idx++) { pointsStarts[leafData.PolygonPointsId[idx]] = true; } // loop over all line-texts. for (int idx = 0; idx < leafData.LineTextPointsId.Count; idx++) { pointsStarts[leafData.LineTextPointsId[idx]] = true; } Dictionary <int, int> pointsBoundaries = new Dictionary <int, int>(); int previous = 0; for (int idx = 1; idx < pointsStarts.Length; idx++) { if (pointsStarts[idx]) { // there is a start here. pointsBoundaries[previous] = idx - previous; previous = idx; } } pointsBoundaries[previous] = pointsStarts.Length - previous; // loop over all points. for (int idx = 0; idx < leafData.PointPointId.Count; idx++) { // get properties. int pointId = leafData.PointPointId[idx]; uint styleId = leafData.PointStyleId[idx]; // get point/style/zoomrange. double x = (double)leafData.PointsX[pointId] / (double)scaleFactor; double y = (double)leafData.PointsY[pointId] / (double)scaleFactor; StylePoint style = _index.PointStyles[styleId]; // build the primitive. Point2D point = new Point2D(x, y, style.Color, style.Size); point.Layer = style.Layer; point.MinZoom = style.MinZoom; point.MaxZoom = style.MaxZoom; dataLists.Add(point); boxes.Add(new BoxF2D(new PointF2D(x, y))); } // loop over all text-points. for (int idx = 0; idx < leafData.TextPointPointId.Count; idx++) { // get properties. int pointId = leafData.TextPointPointId[idx]; uint styleId = leafData.TextPointStyleId[idx]; string text = leafData.TextPointText[idx]; // get point/style/zoomrange. float x = (float)leafData.PointsX[pointId] / (float)scaleFactor; float y = (float)leafData.PointsY[pointId] / (float)scaleFactor; StyleText style = _index.TextStyles[styleId]; // build the primitive. Text2D text2D = new Text2D(x, y, text, style.Color, style.Size); text2D.Layer = style.Layer; text2D.HaloColor = style.HaloColor; text2D.HaloRadius = style.HaloRadius; text2D.MinZoom = style.MinZoom; text2D.MaxZoom = style.MaxZoom; dataLists.Add(text2D); boxes.Add(new BoxF2D(new PointF2D(x, y))); } // loop over all icons. for (int idx = 0; idx < leafData.IconPointId.Count; idx++) { // get properties. int pointId = leafData.IconPointId[idx]; uint imageId = leafData.IconImageId[idx]; // get point/style/zoomrange. double x = (double)leafData.PointsX[pointId] / (double)scaleFactor; double y = (double)leafData.PointsY[pointId] / (double)scaleFactor; byte[] image = _index.IconImage[(int)imageId]; // build the primitive. Icon2D icon = new Icon2D(x, y, image); icon.Layer = 0; // TODO: layer and zoom level. style.MinZoom, style.MaxZoom dataLists.Add(icon); boxes.Add(new BoxF2D(new PointF2D(x, y))); } // loop over all lines. for (int idx = 0; idx < leafData.LinePointsId.Count; idx++) { // get properties. int pointsId = leafData.LinePointsId[idx]; uint styleId = leafData.LineStyleId[idx]; // get points/style/zoomrange. int pointsCount = pointsBoundaries[pointsId]; double[] x = leafData.PointsX.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor); double[] y = leafData.PointsY.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor); StyleLine style = _index.LineStyles[styleId]; // build the primitive. Line2D line = new Line2D(x, y, style.Color, style.Width, style.LineJoin, style.Dashes); line.Layer = style.Layer; line.MinZoom = style.MinZoom; line.MaxZoom = style.MaxZoom; dataLists.Add(line); boxes.Add(new BoxF2D(x, y)); } // loop over all polygons. for (int idx = 0; idx < leafData.PolygonPointsId.Count; idx++) { // get properties. int pointsId = leafData.PolygonPointsId[idx]; uint styleId = leafData.PolygonStyleId[idx]; // get points/style/zoomrange. int pointsCount = pointsBoundaries[pointsId]; double[] x = leafData.PointsX.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor); double[] y = leafData.PointsY.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor); StylePolygon style = _index.PolygonStyles[styleId]; // build the primitive. Polygon2D polygon = new Polygon2D(x, y, style.Color, style.Width, style.Fill); polygon.Layer = style.Layer; polygon.MaxZoom = style.MaxZoom; polygon.MinZoom = style.MinZoom; dataLists.Add(polygon); boxes.Add(new BoxF2D(x, y)); } // loop over all line-texts. for (int idx = 0; idx < leafData.LineTextPointsId.Count; idx++) { // get properties. int pointsId = leafData.LineTextPointsId[idx]; uint styleId = leafData.LineTextStyleId[idx]; string text = leafData.LineTextText[idx]; // get points/style/zoomrange. int pointsCount = pointsBoundaries[pointsId]; double[] x = leafData.PointsX.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor); double[] y = leafData.PointsY.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor); StyleText style = _index.TextStyles[styleId]; // build the primitive. LineText2D lineText = new LineText2D(x, y, style.Color, style.Size, text); lineText.Layer = style.Layer; lineText.Font = style.Font; lineText.HaloColor = style.HaloColor; lineText.HaloRadius = style.HaloRadius; lineText.MinZoom = style.MinZoom; lineText.MaxZoom = style.MaxZoom; dataLists.Add(lineText); boxes.Add(new BoxF2D(x, y)); } return(dataLists); }
/// <summary> /// Set the specified style. /// </summary> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public override void SetStyle(StyleText styleText, Style style) { styleText.ApplyTo(Number); }
/// <summary> /// Set the style. /// </summary> /// <param name="styleBackground">Style for the background.</param> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public virtual void SetStyle(StyleImage styleBackground, StyleText styleText, Style style) { styleBackground.ApplyTo(GetComponent <Image>()); }
protected virtual void OnStyleText(StyleText text) { DefaultAction(text); }
/// <summary> /// Apply style for the specified Text. /// </summary> /// <param name="style">Style for text.</param> /// <param name="component">Text.</param> /// <param name="isInputField">Is transform belongs to the InputField component?</param> /// <returns><c>true</c>, if style was set for children gameobjects, <c>false</c> otherwise.</returns> #if UNITY_5_2 || UNITY_5_3 || UNITY_5_3_OR_NEWER public static bool ApplyTo(StyleText style, TMP_Text component, bool isInputField = false)
public static bool ApplyTo(StyleText style, TextMeshProUGUI component, bool isInputField = false) #endif { if (component == null) { return(false); } if (style.ChangeFont && (style.FontTMPro != null)) { component.font = style.FontTMPro; } if (style.ChangeFontStyle) { component.fontStyle = ConvertStyle(style.FontStyle); } if (style.ChangeLineSpacing) { component.lineSpacing = style.LineSpacing; } if (style.ChangeRichText && (!isInputField)) { component.richText = style.RichText; } if (style.ChangeAlignment && (!isInputField)) { component.alignment = ConvertAlignment(style.Alignment); } if (style.ChangeHorizontalOverflow) { // component.horizontalOverflow = style.HorizontalOverflow; } if (style.ChangeVerticalOverflow) { // component.verticalOverflow = style.VerticalOverflow; } if (style.ChangeBestFit && (!isInputField)) { component.enableAutoSizing = style.BestFit; component.fontSizeMin = style.MinSize; component.fontSizeMax = style.MaxSize; } if (style.ChangeColor) { component.color = style.Color; } if (style.ChangeMaterial) { component.material = style.Material; } component.SetAllDirty(); return(true); }
public void Parse() { SimpleHtmlParser parser = new SimpleHtmlParser(_html); OnDocumentBegin(); while (true) { Element currentElement = parser.Next(); BeginTag beginTag = currentElement as BeginTag; if (beginTag != null) { OnBeginTag(beginTag); continue; } EndTag endTag = currentElement as EndTag; if (endTag != null) { OnEndTag(endTag); continue; } ScriptLiteral literal = currentElement as ScriptLiteral; if (literal != null) { OnScriptLiteral(literal); continue; } Comment comment = currentElement as Comment; if (comment != null) { OnComment(comment); continue; } MarkupDirective markupDirective = currentElement as MarkupDirective; if (markupDirective != null) { OnMarkupDirective(markupDirective); continue; } ScriptText scriptText = currentElement as ScriptText; if (scriptText != null) { OnScriptText(scriptText); continue; } ScriptComment scriptComment = currentElement as ScriptComment; if (scriptComment != null) { OnScriptComment(scriptComment); continue; } StyleText styleText = currentElement as StyleText; if (styleText != null) { OnStyleText(styleText); continue; } StyleUrl styleUrl = currentElement as StyleUrl; if (styleUrl != null) { OnStyleUrl(styleUrl); continue; } StyleImport styleImport = currentElement as StyleImport; if (styleImport != null) { OnStyleImport(styleImport); continue; } StyleComment styleComment = currentElement as StyleComment; if (styleComment != null) { OnStyleComment(styleComment); continue; } StyleLiteral styleLiteral = currentElement as StyleLiteral; if (styleLiteral != null) { OnStyleLiteral(styleLiteral); continue; } Text text = currentElement as Text; if (text != null) { OnText(text); continue; } if (currentElement == null) { OnDocumentEnd(); return; } Debug.Fail("Unrecognized element in LightWeightHTMLDocumentIterator"); } }
/* * ---------------- / CONSTRUCTOR ---------------- */ /* * ---------------- HELPER FUNCTIONS ---------------- */ private void CheckWordsInRun(Run r) /* Scans a run for keywords and stores the keywords with their information in the buffer */ { /* Local Variables */ StyleText styleText; /* Contains the beginning and end positions of a styled token along with the style object to style the token */ LexicalAnalyzer lexer; /* Identifies tokens in the text to be colored */ Token nextToken; /* Pointer to the current token */ int textOffset; /* Start position of the current text ignoring the prefix under a multi-line comment */ int leftRangePointer; /* Pointer to the beginning position of the current token in the text */ int previousLeftRangePointer; /* Stores the left range pointer for adjusting BREAK tokens */ int rightRangePointer; /* Pointer to the end position of the current token in the text */ string currentText; /* Current text to process */ /* / Local Variables */ /* Create new lexical analyzer and start reading tokens */ currentText = r.Text; lexer = new LexicalAnalyzer(currentText); nextToken = lexer.GetToken(); textOffset = 0; rightRangePointer = textOffset + lexer.GetTextPosition() + 1; /* Initial range is from the beginning of the text */ leftRangePointer = rightRangePointer - nextToken.Content.Length; /* to the end of the first read token */ /* If this comes from an unclosed multi-line comment, style everything accordingly */ if (inMultiLineComment) { /* Identify the end of the multi-line comment (either where there is a comment closer or at the end of the string if that is not present) */ if (currentText.Contains("<=")) { rightRangePointer = currentText.IndexOf("<=") + 2; inMultiLineComment = false; } else { rightRangePointer = currentText.Length; } /* Build style text object and add it to the words to style buffer */ styleText = new StyleText { Start = r.ContentStart.GetPositionAtOffset(leftRangePointer), End = r.ContentStart.GetPositionAtOffset(rightRangePointer), Style = multiLineCommentStyle }; styledTextRanges.Add(styleText); /* Reset lexer to ignore the commented out section */ currentText = currentText.Substring(rightRangePointer); lexer = new LexicalAnalyzer(currentText); textOffset = rightRangePointer; nextToken = lexer.GetToken(); rightRangePointer = textOffset + lexer.GetTextPosition() + 1; leftRangePointer = rightRangePointer - nextToken.Content.Length; } /* Find keywords in program by checking each run */ while (nextToken.Type != TokenType.EOF) { /* Adjust range pointers if this is a BREAK token */ if (nextToken.Type == TokenType.BREAK) { /* Store the current value of the left range pointer */ previousLeftRangePointer = leftRangePointer; /* Move the left range pointer further left until it points to a newline (the first newline in the BREAK token) */ while (r.Text[leftRangePointer] != '\n' && r.Text[leftRangePointer] != '\r') { --leftRangePointer; } /* Offset the right range pointer the same amount (add 1 in case a newline is \r\n) */ if (previousLeftRangePointer > leftRangePointer) { rightRangePointer -= previousLeftRangePointer - leftRangePointer + 1; } } /* Adjust range poitners if this is a STRING token */ if (nextToken.Type == TokenType.STRING) { leftRangePointer -= 2; /* Offset for the two quotes in the string */ } /* Add any tokens with a recognized type to the words to style buffer */ if (tokenTypeStyleDict.ContainsKey(nextToken.Type)) { styleText = new StyleText { Start = r.ContentStart.GetPositionAtOffset(leftRangePointer), End = r.ContentStart.GetPositionAtOffset(rightRangePointer), Style = tokenTypeStyleDict[nextToken.Type] }; styledTextRanges.Add(styleText); } /* Add any other recognized strings to the words to style buffer */ else if (wordStyleDict.ContainsKey(nextToken.Content)) { styleText = new StyleText { Start = r.ContentStart.GetPositionAtOffset(leftRangePointer), End = r.ContentStart.GetPositionAtOffset(rightRangePointer), Style = wordStyleDict[nextToken.Content] }; styledTextRanges.Add(styleText); } /* Get the next token and update the left and right pointers accordingly */ nextToken = lexer.GetToken(); rightRangePointer = textOffset + lexer.GetTextPosition() + 1; leftRangePointer = rightRangePointer - nextToken.Content.Length; } /* Style comments */ foreach (KeyValuePair <int, string> positionCommentPair in lexer.SingleLineCommentStartPositionMap) { styleText = new StyleText { Start = r.ContentStart.GetPositionAtOffset(positionCommentPair.Key), End = r.ContentStart.GetPositionAtOffset(textOffset + positionCommentPair.Key + positionCommentPair.Value.Length), Style = singleLineCommentStyle }; styledTextRanges.Add(styleText); } foreach (KeyValuePair <int, string> positionCommentPair in lexer.MultiLineCommentStartPositionMap) { /* Check if the multi-line comment ends */ inMultiLineComment = !positionCommentPair.Value.Contains("<="); styleText = new StyleText { Start = r.ContentStart.GetPositionAtOffset(positionCommentPair.Key), End = r.ContentStart.GetPositionAtOffset(textOffset + positionCommentPair.Key + positionCommentPair.Value.Length), Style = multiLineCommentStyle, }; styledTextRanges.Add(styleText); } }
protected virtual void OnStyleText(StyleText styleText) { }
protected override void OnStyleText(StyleText styleText) { Emit(styleText); base.OnStyleText(styleText); }
/// <summary> /// Set the specified style. /// </summary> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public virtual void SetStyle(StyleText styleText, Style style) { // do nothing }
/// <summary> /// Set the style. /// </summary> /// <param name="styleBackground">Style for the background.</param> /// <param name="styleText">Style for the text.</param> /// <param name="style">Full style data.</param> public override void SetStyle(StyleImage styleBackground, StyleText styleText, Style style) { base.SetStyle(styleBackground, styleText, style); styleText.ApplyTo(Name); }
private void CheckWordsInRun(Run r) /* Scans a run for keywords and stores the keywords with their information in the buffer */ { /* Local Variables */ StyleText styleText; int startIndex; int endIndex; int i; string hasStyleReturn; string word; string lastWord; /* / Local Variables */ startIndex = 0; endIndex = 0; /* Find special words */ for (i = 0; i < currentText.Length; ++i) { if (char.IsWhiteSpace(currentText[i])) { /* Check to see if we're at the end of a word (because we're on whitespace and the character before is not whitespace) */ if (i > 0 && !(char.IsWhiteSpace(currentText[i - 1]))) { endIndex = i - 1; word = currentText.Substring(startIndex, endIndex - startIndex + 1); hasStyleReturn = HasStyle(word); /* If the word is marked to be styled */ if (hasStyleReturn != null) { styleText = new StyleText(); styleText.Start = r.ContentStart.GetPositionAtOffset(startIndex, LogicalDirection.Forward); /* Get starting position in textbox */ /* Get ending position in textbox */ if (hasStyleReturn == word) { styleText.End = r.ContentStart.GetPositionAtOffset(endIndex + 1, LogicalDirection.Backward); } else { styleText.End = r.ContentStart.GetPositionAtOffset(endIndex + 1 - (word.Length - hasStyleReturn.Length), LogicalDirection.Backward); } /* Store the word itself and the styler instance (lookup from dictionary) */ styleText.Word = word; styleText.Style = wordStyleDict[hasStyleReturn]; /* Add the new StyleText instance containing the word's position, content, and style to the buffer */ keywordBuffer.Add(styleText); } } startIndex = i + 1; } } /* The previous loop doesn't deal with the last word */ lastWord = currentText.Substring(startIndex, currentText.Length - startIndex); /* Process is the same as above */ hasStyleReturn = HasStyle(lastWord); if (hasStyleReturn != null) { styleText = new StyleText(); styleText.Start = r.ContentStart.GetPositionAtOffset(startIndex, LogicalDirection.Forward); if (hasStyleReturn == lastWord) { styleText.End = r.ContentStart.GetPositionAtOffset(endIndex + 1, LogicalDirection.Backward); } else { styleText.End = r.ContentStart.GetPositionAtOffset(endIndex + 1 - (lastWord.Length - hasStyleReturn.Length), LogicalDirection.Backward); } styleText.Word = lastWord; styleText.Style = wordStyleDict[hasStyleReturn]; keywordBuffer.Add(styleText); } }