/// <summary> /// Makes a valid source code name for the name of a given Kimono Object. /// </summary> /// <returns>The element name valid for use in source code.</returns> /// <param name="name">The source Kimono Object name.</param> public static string MakeElementName(string name) { var elementName = ""; var isFirstLetter = true; // Scan all characters of the incomming characters foreach (char c in name) { // Is this a valid character? if (Kimono.CharIsNumber(c)) { // Is this the first letter? if (isFirstLetter) { // Yes, not valid at the start of a name elementName += $"Skia{c}"; } else { // No, always valid elementName += c; } } else if (Kimono.CharIsLetter(c)) { // Always valid, add elementName += c; } // Clear state isFirstLetter = false; } // Was a name generated at all? if (elementName == "") { // No, make one elementName = $"skiaElement{++NextElementNumber}"; } else if (AddNumberToElementNames) { // Append number to element name elementName = $"{elementName}{++NextElementNumber}"; } // Has this name already been used? while (NameUsed(elementName)) { // Increment the name elementName = Kimono.IncrementName(elementName).Replace(" ", ""); } // Save name in the collection of used names UsedNames.Add(elementName); // Return resulting name return(elementName); }
public KimonoTextBase() { // Preregister all of the objects with the database otherwise loading a saved // file will die. Register <SKPoint>(); Register <KimonoBezierPoint>(); Register <KimonoHandle>(); Register <KimonoBlur>(); Register <KimonoShadow>(); Register <KimonoProperty>(); Register <KimonoPropertyBoolean>(); Register <KimonoPropertyColor>(); Register <KimonoPropertyConnection>(); Register <KimonoPropertyGradient>(); Register <KimonoPropertyLibrary>(); Register <KimonoPropertyNumber>(); Register <KimonoPropertyRect>(); Register <KimonoPropertyStyle>(); Register <KimonoPropertyText>(); Register <KimonoShape>(); Register <KimonoShapeArrow>(); Register <KimonoShapeBezier>(); Register <KimonoShapeGroup>(); Register <KimonoShapeLine>(); Register <KimonoShapeOval>(); Register <KimonoShapePolygon>(); Register <KimonoShapeRect>(); Register <KimonoShapeRoundRect>(); Register <KimonoShapeStar>(); Register <KimonoShapeText>(); Register <KimonoShapeTriangle>(); Register <KimonoShapeVector>(); Register <KimonoColor>(); Register <KimonoGradient>(); Register <KimonoStyle>(); Register <KimonoPortfolio>(); Register <KimonoSketch>(); // Add serialization of KimonoCore and SkiaSharp objects to the database this.RequestCustomSerialization += (serializer, obj) => { var result = ""; // Take action based on the serializer type switch (serializer) { case "SKColor": try { if (obj == null) { // Default to white result = "#FFFFFFFF"; } else { // Encode color result = Kimono.ColorToHex((SKColor)obj, true); } } catch { // Default to white result = "#FFFFFFFF"; } break; } // Return results return(result); }; // Add deserialization of KimonoCore and SkiaSharp objects to the database this.RequestCustomDeserialization += (serializer, value) => { object result = null; // Take action based on the serializer type switch (serializer) { case "SKColor": try { if (string.IsNullOrEmpty(value)) { // Default to white result = KimonoColor.White; } else { // Decode color result = KimonoCore.Kimono.HexToColor(value); } } catch { // Default to white result = KimonoColor.White; } break; } // Return results return(result); }; }