├── .gitattributes ├── .gitignore ├── App.config ├── App.xaml ├── App.xaml.cs ├── LICENSE ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── README.md ├── Readme.png ├── TextOnPath.cs ├── TextOnPath.csproj └── TextOnPath.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | -------------------------------------------------------------------------------- /App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace Petzold2 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 gomi42 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 15 | M 50,50 C 100,0 200,100 250,50 16 | 19 | 21 | 25 | 28 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 81 | 82 | 84 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 125 | 126 | 128 | 131 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace TextOnPathTest 17 | { 18 | /// 19 | /// Interaction logic for MainWindow.xaml 20 | /// 21 | public partial class MainWindow : Window 22 | { 23 | public MainWindow() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("Petzold2")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("Petzold2")] 15 | [assembly: AssemblyCopyright("Copyright © 2020")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TextOnPathTest.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TextOnPathTest.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace TextOnPathTest.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TextOnPath 2 | WPF control that displays text along a given path 3 | 4 | ![intro](/Readme.png) 5 | 6 | # Features 7 | * define the path in several different ways like PathGeometry, Geometry, PathFigure, Line, Rectangle, Ellipse 8 | * show text warped or unwarped 9 | * stretch the text along the full path (=> automatic font size) or use the given FontSize (text might be shorter or longer than the path) 10 | * set fill and stroke independently 11 | * supports gradients of any kind that is applied to the result as a single entity (not each character individually) 12 | 13 | # Usage 14 | Define paths in your resources... 15 | ```xaml 16 | 17 | 19 | M 50,50 C 100,0 200,100 250,50 20 | 23 | 25 | 29 | 32 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | ``` 44 | ...and use them 45 | ```xaml 46 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | ``` 65 | 66 | or directy assign the path (again any type of Geometry or PathFigure will work) to the Path property of the TextOnPath control 67 | ```xaml 68 | 78 | 79 | 81 | 84 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | ``` 98 | 99 | # Notes 100 | * because of its simplicity the TextOnPath control is part of the test application 101 | * this control is based on Charles Petzold's work, ideas and code 102 | -------------------------------------------------------------------------------- /Readme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gomi42/TextOnPath/17da7df6bddbe7330ccf0b48ffe63639508c163a/Readme.png -------------------------------------------------------------------------------- /TextOnPath.cs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2020 Michael Göricke 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // This control is based on Charles Petzold's work, ideas and code. This control 24 | // combines warped and unwarped text into one single control and adds some more 25 | // features: 26 | // - define the path in some more ways than just a PathFigure 27 | // - show text warped or unwarped 28 | // - stretch the text along the full path (=> automatic font size) or use the 29 | // given FontSize (text might be shorter or longer than the path) 30 | 31 | using System; 32 | using System.Collections.Generic; 33 | using System.ComponentModel; 34 | using System.Globalization; 35 | using System.Windows; 36 | using System.Windows.Controls; 37 | using System.Windows.Documents; 38 | using System.Windows.Media; 39 | 40 | namespace Control.TextOnPath 41 | { 42 | public class TextOnPath : FrameworkElement 43 | { 44 | private delegate Point ProcessPoint(Point pointSrc); 45 | 46 | private Typeface typeface; 47 | private List formattedChars = new List(); 48 | private double pathLength; 49 | private double textLength; 50 | private PathGeometry paintGeometry; 51 | 52 | public TextOnPath() 53 | { 54 | typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); 55 | } 56 | 57 | public static readonly DependencyProperty FontFamilyProperty = 58 | TextElement.FontFamilyProperty.AddOwner(typeof(TextOnPath), 59 | new FrameworkPropertyMetadata(OnFontPropertyChanged)); 60 | 61 | public FontFamily FontFamily 62 | { 63 | get => (FontFamily)GetValue(FontFamilyProperty); 64 | set => SetValue(FontFamilyProperty, value); 65 | } 66 | 67 | public static readonly DependencyProperty FontSizeProperty = 68 | TextElement.FontSizeProperty.AddOwner(typeof(TextOnPath), 69 | new FrameworkPropertyMetadata(OnFontPropertyChanged)); 70 | 71 | public double FontSize 72 | { 73 | get => (double)GetValue(FontSizeProperty); 74 | set => SetValue(FontSizeProperty, value); 75 | } 76 | 77 | public static readonly DependencyProperty FontStyleProperty = 78 | TextElement.FontStyleProperty.AddOwner(typeof(TextOnPath), 79 | new FrameworkPropertyMetadata(OnFontPropertyChanged)); 80 | 81 | public FontStyle FontStyle 82 | { 83 | get => (FontStyle)GetValue(FontStyleProperty); 84 | set => SetValue(FontStyleProperty, value); 85 | } 86 | 87 | public static readonly DependencyProperty FontWeightProperty = 88 | TextElement.FontWeightProperty.AddOwner(typeof(TextOnPath), 89 | new FrameworkPropertyMetadata(OnFontPropertyChanged)); 90 | 91 | public FontWeight FontWeight 92 | { 93 | get => (FontWeight)GetValue(FontWeightProperty); 94 | set => SetValue(FontWeightProperty, value); 95 | } 96 | 97 | public static readonly DependencyProperty FontStretchProperty = 98 | TextElement.FontStretchProperty.AddOwner(typeof(TextOnPath), 99 | new FrameworkPropertyMetadata(OnFontPropertyChanged)); 100 | 101 | public FontStretch FontStretch 102 | { 103 | get => (FontStretch)GetValue(FontStretchProperty); 104 | set => SetValue(FontStretchProperty, value); 105 | } 106 | 107 | static void OnFontPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 108 | { 109 | (obj as TextOnPath).OnFontPropertyChanged(); 110 | } 111 | 112 | public static readonly DependencyProperty TextProperty = 113 | TextBlock.TextProperty.AddOwner(typeof(TextOnPath), 114 | new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure, OnTextPropertyChanged)); 115 | 116 | public string Text 117 | { 118 | get => (string)GetValue(TextProperty); 119 | set => SetValue(TextProperty, value); 120 | } 121 | 122 | static void OnTextPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 123 | { 124 | (obj as TextOnPath).PrepareText(); 125 | } 126 | 127 | public static readonly DependencyProperty PathProperty = 128 | DependencyProperty.Register("Path", typeof(object), typeof(TextOnPath), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure, OnPathPropertyChanged)); 129 | 130 | public object Path 131 | { 132 | get => GetValue(PathProperty); 133 | set => SetValue(PathProperty, value); 134 | } 135 | 136 | private static void OnPathPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 137 | { 138 | (d as TextOnPath).OnPathPropertyChanged(); 139 | } 140 | 141 | public static readonly DependencyProperty WarpProperty = 142 | DependencyProperty.Register("Warp", typeof(bool), typeof(TextOnPath), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure, OnWarpPropertyChanged)); 143 | 144 | public bool Warp 145 | { 146 | get => (bool)GetValue(WarpProperty); 147 | set => SetValue(WarpProperty, value); 148 | } 149 | 150 | private static void OnWarpPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 151 | { 152 | (d as TextOnPath).CreatePaintGeometry(); 153 | } 154 | 155 | public static readonly DependencyProperty StretchProperty = 156 | DependencyProperty.Register("Stretch", typeof(bool), typeof(TextOnPath), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender)); 157 | 158 | public bool Stretch 159 | { 160 | get => (bool)GetValue(StretchProperty); 161 | set => SetValue(StretchProperty, value); 162 | } 163 | 164 | public static readonly DependencyProperty FillProperty = 165 | DependencyProperty.Register("Fill", typeof(Brush), typeof(TextOnPath), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); 166 | 167 | public Brush Fill 168 | { 169 | get => (Brush)GetValue(FillProperty); 170 | set => SetValue(FillProperty, value); 171 | } 172 | 173 | public static readonly DependencyProperty StrokeProperty = 174 | DependencyProperty.Register("Stroke", typeof(Brush), typeof(TextOnPath), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); 175 | 176 | public Brush Stroke 177 | { 178 | get { return (Brush)GetValue(StrokeProperty); } 179 | set { SetValue(StrokeProperty, value); } 180 | } 181 | 182 | [Category("Appearance")] 183 | public static readonly DependencyProperty StrokeThicknessProperty = 184 | DependencyProperty.Register("StrokeThickness", typeof(double), typeof(TextOnPath), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender)); 185 | 186 | public double StrokeThickness 187 | { 188 | get => (double)GetValue(StrokeThicknessProperty); 189 | set => SetValue(StrokeThicknessProperty, value); 190 | } 191 | 192 | private void OnFontPropertyChanged() 193 | { 194 | typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); 195 | PrepareText(); 196 | InvalidateVisual(); 197 | } 198 | 199 | private void PrepareText() 200 | { 201 | formattedChars.Clear(); 202 | textLength = 0; 203 | 204 | if (Text == null) 205 | { 206 | return; 207 | } 208 | 209 | foreach (char ch in Text) 210 | { 211 | FormattedText formattedText = new FormattedText(ch.ToString(), 212 | CultureInfo.CurrentCulture, 213 | FlowDirection.LeftToRight, 214 | typeface, 215 | FontSize, 216 | Brushes.Black, 217 | 96); 218 | 219 | formattedChars.Add(formattedText); 220 | textLength += formattedText.WidthIncludingTrailingWhitespace; 221 | } 222 | 223 | CreatePaintGeometry(); 224 | } 225 | 226 | private void OnPathPropertyChanged() 227 | { 228 | pathLength = GetPathFigureLength(); 229 | CreatePaintGeometry(); 230 | } 231 | 232 | protected override Size MeasureOverride(Size availableSize) 233 | { 234 | if (paintGeometry == null) 235 | { 236 | return base.MeasureOverride(availableSize); 237 | } 238 | 239 | Rect rect = paintGeometry.Bounds; 240 | 241 | return rect.Size; 242 | } 243 | 244 | protected override void OnRender(DrawingContext dc) 245 | { 246 | if (paintGeometry == null || pathLength == 0 || textLength == 0) 247 | { 248 | return; 249 | } 250 | 251 | dc.DrawGeometry(Fill, new Pen(Stroke, StrokeThickness), paintGeometry); 252 | } 253 | 254 | private void CreatePaintGeometry() 255 | { 256 | if (Path == null) 257 | { 258 | return; 259 | } 260 | 261 | double scalingFactor; 262 | 263 | if (Stretch) 264 | { 265 | scalingFactor = pathLength / textLength; 266 | } 267 | else 268 | { 269 | scalingFactor = 1; 270 | } 271 | 272 | double progress = 0; 273 | 274 | PathGeometry pathGeometry = GetPathGeometry(); 275 | 276 | paintGeometry = new PathGeometry(); 277 | paintGeometry.FillRule = FillRule.Nonzero; 278 | 279 | foreach (FormattedText formText in formattedChars) 280 | { 281 | var geometry = formText.BuildGeometry(new Point()); 282 | geometry = formText.BuildGeometry(new Point()).CloneCurrentValue(); 283 | 284 | if (Warp) 285 | { 286 | ModifyGeometryPoints(geometry, 287 | delegate (Point pointSrc) 288 | { 289 | double fractionLength = Math.Max(0, Math.Min(1, scalingFactor * (progress + pointSrc.X) / pathLength)); 290 | double offsetFromBaseline = scalingFactor * (formText.Baseline - pointSrc.Y); 291 | 292 | pathGeometry.GetPointAtFractionLength(fractionLength, out Point pathPoint, out Point pathTangent); 293 | double angle = Math.Atan2(pathTangent.Y, pathTangent.X); 294 | 295 | Point pointDst = new Point(); 296 | pointDst.X = pathPoint.X + offsetFromBaseline * Math.Sin(angle); 297 | pointDst.Y = pathPoint.Y - offsetFromBaseline * Math.Cos(angle); 298 | 299 | return pointDst; 300 | }); 301 | 302 | progress += formText.WidthIncludingTrailingWhitespace; 303 | } 304 | else 305 | { 306 | double width = scalingFactor * formText.WidthIncludingTrailingWhitespace; 307 | double baseline = scalingFactor * formText.Baseline; 308 | var charHalfWidthPercent = width / 2 / pathLength; 309 | progress += charHalfWidthPercent; 310 | 311 | pathGeometry.GetPointAtFractionLength(progress, out Point point, out Point tangent); 312 | 313 | Matrix matrix = Matrix.Identity; 314 | matrix.Scale(scalingFactor, scalingFactor); 315 | matrix.RotateAt(Math.Atan2(tangent.Y, tangent.X) * 180 / Math.PI, width / 2, baseline); 316 | matrix.Translate(point.X - width / 2, point.Y - baseline); 317 | geometry.Transform = new MatrixTransform(matrix); 318 | 319 | //ProcessGeometryPoints(geometry, 320 | // delegate (Point pointSrc) 321 | // { 322 | // pathGeometry.GetPointAtFractionLength(progress, out Point point, out Point tangent); 323 | 324 | // Matrix matrix = Matrix.Identity; 325 | // matrix.Scale(scalingFactor, scalingFactor); 326 | // matrix.RotateAt(Math.Atan2(tangent.Y, tangent.X) * 180 / Math.PI, width / 2, baseline); 327 | // matrix.Translate(point.X - width / 2, point.Y - baseline); 328 | 329 | // return pointSrc * matrix; 330 | // }); 331 | 332 | progress += charHalfWidthPercent; 333 | } 334 | 335 | paintGeometry.AddGeometry(geometry); 336 | } 337 | 338 | Rect boundsRect = paintGeometry.Bounds; 339 | 340 | //ModifyGeometryPoints(newGeometry, 341 | // delegate (Point pointSrc) 342 | // { 343 | // Point pointDst = new Point(); 344 | // pointDst.X = pointSrc.X - boundsRect.Left; 345 | // pointDst.Y = pointSrc.Y - boundsRect.Top; 346 | 347 | // return pointDst; 348 | // }); 349 | 350 | paintGeometry.Transform = new TranslateTransform(-boundsRect.Left, -boundsRect.Top); 351 | } 352 | 353 | private PathGeometry GetPathGeometry() 354 | { 355 | PathGeometry pathGeometry = new PathGeometry(); 356 | 357 | if (Path is PathFigure figure) 358 | { 359 | pathGeometry.Figures.Add(figure); 360 | } 361 | else 362 | { 363 | pathGeometry.AddGeometry(Path as Geometry); 364 | } 365 | 366 | return pathGeometry; 367 | } 368 | 369 | private void ModifyGeometryPoints(Geometry geometry, ProcessPoint callback) 370 | { 371 | switch (geometry) 372 | { 373 | case GeometryGroup group: 374 | { 375 | foreach (var child in group.Children) 376 | { 377 | ModifyGeometryPoints(child, callback); 378 | } 379 | 380 | break; 381 | } 382 | 383 | case PathGeometry path: 384 | { 385 | foreach (var figure in path.Figures) 386 | { 387 | figure.StartPoint = callback(figure.StartPoint); 388 | 389 | foreach (var segment in figure.Segments) 390 | { 391 | switch (segment) 392 | { 393 | case LineSegment line: 394 | { 395 | line.Point = callback(line.Point); 396 | break; 397 | } 398 | 399 | case BezierSegment bezier: 400 | { 401 | bezier.Point1 = callback(bezier.Point1); 402 | bezier.Point2 = callback(bezier.Point2); 403 | bezier.Point3 = callback(bezier.Point3); 404 | break; 405 | } 406 | 407 | case PolyLineSegment polyLine: 408 | { 409 | for (int i = 0; i < polyLine.Points.Count; i++) 410 | { 411 | polyLine.Points[i] = callback(polyLine.Points[i]); 412 | } 413 | break; 414 | } 415 | 416 | case PolyBezierSegment polyBezier: 417 | { 418 | for (int i = 0; i < polyBezier.Points.Count; i += 3) 419 | { 420 | polyBezier.Points[i] = callback(polyBezier.Points[i]); 421 | polyBezier.Points[i + 1] = callback(polyBezier.Points[i + 1]); 422 | polyBezier.Points[i + 2] = callback(polyBezier.Points[i + 2]); 423 | } 424 | break; 425 | } 426 | } 427 | } 428 | } 429 | 430 | break; 431 | } 432 | } 433 | } 434 | 435 | private double GetPathFigureLength() 436 | { 437 | if (Path == null) 438 | { 439 | return 0; 440 | } 441 | 442 | PathFigure pathFigure; 443 | 444 | if (Path is PathFigure figure) 445 | { 446 | pathFigure = figure; 447 | } 448 | else 449 | { 450 | var pathGeometry = new PathGeometry(); 451 | pathGeometry.AddGeometry(Path as Geometry); 452 | 453 | pathFigure = pathGeometry.Figures[0]; 454 | } 455 | 456 | if (pathFigure == null) 457 | { 458 | return 0; 459 | } 460 | 461 | bool isAlreadyFlattened = true; 462 | 463 | foreach (PathSegment pathSegment in pathFigure.Segments) 464 | { 465 | if (!(pathSegment is PolyLineSegment) && !(pathSegment is LineSegment)) 466 | { 467 | isAlreadyFlattened = false; 468 | break; 469 | } 470 | } 471 | 472 | PathFigure pathFigureFlattened = isAlreadyFlattened ? pathFigure : pathFigure.GetFlattenedPathFigure(); 473 | double length = 0; 474 | Point from = pathFigureFlattened.StartPoint; 475 | 476 | foreach (PathSegment pathSegment in pathFigureFlattened.Segments) 477 | { 478 | switch (pathSegment) 479 | { 480 | case LineSegment line: 481 | { 482 | Point to = line.Point; 483 | length += (to - from).Length; 484 | from = to; 485 | 486 | break; 487 | } 488 | 489 | case PolyLineSegment poly: 490 | { 491 | PointCollection pointCollection = poly.Points; 492 | 493 | foreach (Point to in pointCollection) 494 | { 495 | length += (to - from).Length; 496 | from = to; 497 | } 498 | 499 | break; 500 | } 501 | } 502 | } 503 | 504 | return length; 505 | } 506 | } 507 | } 508 | -------------------------------------------------------------------------------- /TextOnPath.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6878DB73-C1AB-4B9E-AC44-14CB50805685} 8 | WinExe 9 | TextOnPathTest 10 | TextOnPath 11 | v4.8 12 | 512 13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 4 15 | true 16 | true 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 4.0 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | MSBuild:Compile 56 | Designer 57 | 58 | 59 | 60 | MSBuild:Compile 61 | Designer 62 | 63 | 64 | App.xaml 65 | Code 66 | 67 | 68 | MainWindow.xaml 69 | Code 70 | 71 | 72 | 73 | 74 | Code 75 | 76 | 77 | True 78 | True 79 | Resources.resx 80 | 81 | 82 | True 83 | Settings.settings 84 | True 85 | 86 | 87 | ResXFileCodeGenerator 88 | Resources.Designer.cs 89 | 90 | 91 | SettingsSingleFileGenerator 92 | Settings.Designer.cs 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /TextOnPath.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextOnPath", "TextOnPath.csproj", "{6878DB73-C1AB-4B9E-AC44-14CB50805685}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6878DB73-C1AB-4B9E-AC44-14CB50805685}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {6878DB73-C1AB-4B9E-AC44-14CB50805685}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {6878DB73-C1AB-4B9E-AC44-14CB50805685}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {6878DB73-C1AB-4B9E-AC44-14CB50805685}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C84896AD-421E-4FB8-9AE0-EBD599365789} 24 | EndGlobalSection 25 | EndGlobal 26 | --------------------------------------------------------------------------------