Skip to content

Commit

Permalink
Add support of text stroke
Browse files Browse the repository at this point in the history
feature(label stroke): add stroke for simple colours, need to fix gradient colors

# Conflicts:
#	Source/Model/Nodes/SVGText.swift

code refactoring, need to fix position for plain stroke labels

# Conflicts:
#	Source/Model/Nodes/SVGText.swift

chagne stroke width to ratio of font size, add getFont method

change plain stroke label frame

code refactoring

add all in one, stoke and fill case

add locations to gradient funcs

add macOS support

fix position change bug, change getLabelSize to getHeightOfLabel

fix bug with background for filled label

change Linear Gradient alignmentGuide, fix bounds for stroke label and stroke gradient

change position code of gradient and stroke labels, fix decreasing height of stroke label bug

code refactoring

fix position for OSX and ios

Add radial gradient support for iOS and OSX

code refactoring

change tabs to 4 spaces

code refactoring

code refactoring

refactoring: fix createOneColorStrokeLabel

fix createGradientStrokeLabel

fix createFillGradientLabel

fix createRadialGradientStrokeLabel and createRadialGradientFillLabel

fix createOneColorFillLabel, codestyle fix

delete getLabelHeight, leave only one version of SVGGUITextView

add getStrokeBounds func

code refactoring

fix codestyle

fix bugs
  • Loading branch information
Ruslan Abbasov committed Jul 14, 2022
1 parent bcc3e54 commit 704dfe9
Show file tree
Hide file tree
Showing 3 changed files with 518 additions and 12 deletions.
27 changes: 27 additions & 0 deletions SVGView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
4460F8F6287C310A00E50E11 /* SVGGUITextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4460F8F5287C310A00E50E11 /* SVGGUITextView.swift */; };
4460F8F7287C310A00E50E11 /* SVGGUITextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4460F8F5287C310A00E50E11 /* SVGGUITextView.swift */; };
5815294025B6C8F600E8D23A /* SVGPaint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5815293F25B6C8F600E8D23A /* SVGPaint.swift */; };
5815294425B6C90F00E8D23A /* SVGColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5815294325B6C90F00E8D23A /* SVGColor.swift */; };
5815298A25B752E600E8D23A /* SVGPreserveAspectRatio.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5815298925B752E600E8D23A /* SVGPreserveAspectRatio.swift */; };
Expand Down Expand Up @@ -134,6 +136,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
4460F8F5287C310A00E50E11 /* SVGGUITextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SVGGUITextView.swift; sourceTree = "<group>"; };
5815293F25B6C8F600E8D23A /* SVGPaint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SVGPaint.swift; sourceTree = "<group>"; };
5815294325B6C90F00E8D23A /* SVGColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SVGColor.swift; sourceTree = "<group>"; };
5815298925B752E600E8D23A /* SVGPreserveAspectRatio.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SVGPreserveAspectRatio.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -296,6 +299,7 @@
children = (
5B1F462F251348F70068EF42 /* MBezierPath+Extension_macOS.swift */,
58A664F3283E96E700F1F6FD /* UIExtensions.swift */,
4460F8F5287C310A00E50E11 /* SVGGUITextView.swift */,
);
path = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -463,6 +467,7 @@
5BE3321924E1446A00BB0D60 /* Sources */,
5BE3321A24E1446A00BB0D60 /* Frameworks */,
5BE3321B24E1446A00BB0D60 /* Resources */,
44FD79C9287D475F00AE8899 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -546,6 +551,26 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
44FD79C9287D475F00AE8899 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"error: SwiftLint does not exist, download it from https://github.com/realm/SwiftLint\"\n exit 1\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
5BE3321924E1446A00BB0D60 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -589,6 +614,7 @@
586D5C2C284295C400C79E0E /* SVGTextParser.swift in Sources */,
586D5C3228429BE600C79E0E /* SVGShapeParser.swift in Sources */,
5B1017EC25358E5600105E9A /* SVGLength.swift in Sources */,
4460F8F6287C310A00E50E11 /* SVGGUITextView.swift in Sources */,
58869B6D25B5C52D00F6E324 /* Serializer.swift in Sources */,
5BE3327224E144B200BB0D60 /* SVGStroke.swift in Sources */,
5BE3326324E144B200BB0D60 /* SVGLine.swift in Sources */,
Expand Down Expand Up @@ -633,6 +659,7 @@
58A66521283E99FB00F1F6FD /* Serializations.swift in Sources */,
58A66507283E99AC00F1F6FD /* SVGPolygon.swift in Sources */,
586D5C30284298BB00C79E0E /* SVGImageParser.swift in Sources */,
4460F8F7287C310A00E50E11 /* SVGGUITextView.swift in Sources */,
58A664FA283E991E00F1F6FD /* SVGLength.swift in Sources */,
58A6650B283E99B700F1F6FD /* SVGRect.swift in Sources */,
58A66520283E99F900F1F6FD /* Serializable.swift in Sources */,
Expand Down
28 changes: 16 additions & 12 deletions Source/Model/Nodes/SVGText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ public class SVGText: SVGNode, ObservableObject {
serializer.add("stroke", stroke)
super.serialize(serializer)
}

public func contentView() -> some View {
SVGTextView(model: self)
}

public func contentView() -> some View {
if self.stroke != nil || self.fill != nil {
return AnyView(SVGGUITextView(model: self))
} else {
return AnyView(SVGTextView(model: self))
}
}
}

struct SVGTextView: View {
Expand All @@ -51,13 +55,13 @@ struct SVGTextView: View {

private func filledText(fill: SVGPaint?) -> some View {
Text(model.text)
.font(model.font?.toSwiftUI())
.lineLimit(1)
.alignmentGuide(.leading) { d in d[model.textAnchor] }
.alignmentGuide(VerticalAlignment.top) { d in d[VerticalAlignment.firstTextBaseline] }
.position(x: 0, y: 0) // just to specify that positioning is global, actual coords are in transform
.apply(paint: fill)
.transformEffect(model.transform)
.frame(alignment: .topLeading)
.font(model.font?.toSwiftUI())
.lineLimit(1)
.alignmentGuide(.leading) { d in d[model.textAnchor] }
.alignmentGuide(VerticalAlignment.top) { d in d[VerticalAlignment.firstTextBaseline] }
.position(x: 0, y: 0) // just to specify that positioning is global, actual coords are in transform
.apply(paint: fill)
.transformEffect(model.transform)
.frame(alignment: .topLeading)
}
}
Loading

0 comments on commit 704dfe9

Please sign in to comment.