SVG矢量文字笔画未“完成”

如何解决SVG矢量文字笔画未“完成”

为什么矢量文字上的笔画在某些字母角上没有完成?我在Illustrator中以1px的笔触制作了此SVG,并以图片的形式显示了该图片。我尝试使用不同的字体,但是仍然遇到相同的问题。我还尝试了vector-effect:non-scaling-stroke;这帮助了一点。我测试了不同的笔划偏移量,但也没有运气。

here is an example

path{
stroke-dasharray:500;
opacity:10;
stroke:#000;
animation: animate 4s cubic-bezier(.69,.71,.69,.71);
}

@keyframes animate{
    
    0%{

        opacity=0;
    stroke-dashoffset:500;
    }
    
20%{

        opacity=0;
    stroke-dashoffset:500;
    }
    

        100%{
        opacity:10;
    stroke-dashoffset:0;
    
    }
    
}
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 0 363.5 122.5" style="enable-background:new 0 0 363.5 122.5;" xml:space="preserve">
<style type="text/css">
    .st0{fill:#AF174A;}
    .st1{stroke:#000000;stroke-miterlimit:10;}
</style>
<polygon class="st0" points="189.6,-14.4 189.5,-14.5 189.5,-14.4 "/>
<g>
    <path class="st1" d="M121.9,104.7l-18.1-17.8v17.8h-1.1V67.4h1.1v17.9l18.1-17.9h1.4l-18.9,18.7l18.9,18.7H121.9z"/>
    <path class="st1" d="M148.7,67.4v1h-17.2v17.2h15.6v1h-15.6v17.2h17.2v1h-18.2V67.4H148.7z"/>
    <path class="st1" d="M164.8,104.7l-10-37.3h1.2l9.4,35.2l10.9-35.2h1.2l11,35.4l9.4-35.4h1.2l-10,37.3h-1.1l-11.1-35.6l-11.1,35.6
        H164.8z"/>
    <path class="st1" d="M225.2,67.4v1H208v17.2h15.6v1H208v17.2h17.2v1H207V67.4H225.2z"/>
    <path class="st1" d="M258.2,67.5h1.1v37.3h-1.1L235,69.4v35.3h-1.1V67.5h1.1l23.2,35.3V67.5z"/>
</g>
</svg>

enter image description here

解决方法

您对我不太确定的SVG规范的细节感到困惑。它是错误还是功能?自己决定。

您使用的路径以 closepath 命令d结束其z属性。 spec清楚地表明,无论是否使用closepath,在该路径终点处的笔触行为都不同:

当子路径以“ closepath”结尾时,其行为与通过“ lineto”命令“手动”关闭子路径时所发生的行为不同,它们是如何实现stroke-linejoinstroke-linecap的。使用“ closepath”时,使用stroke-linejoin的当前值,将子路径的最后一段的结尾与子路径的初始段的起点“连接”。如果您改为通过“ lineto”命令“手动”关闭子路径,则不会合并第一段的开头和最后一段的结尾,而是使用stroke-linecap的当前值来分别设置上限。>

在下面的示例中,您可以比较关闭或不关闭路径的效果。

path {
    fill: none;
    stroke: black;
    stroke-width: 20;
}
<svg viewBox="0 0 300 100">
    <path d="M20 20 H 80 V 80 H 20 V 20" />
    <path d="M120 20 H 180 V 80 H 120 z" />
</svg>

stroke-linecap的默认值为butt,这意味着笔触仅垂直于笔划的末端结束。因此,在不闭合路径的情况下,在外角处仍然存在间隙,如果应用线连接,则该间隙会绘制斜接。

现在,您的代码具有 closepath命令。为什么最后的斜接仍然没有画出来?您必须仔细阅读spec的虚线绘制算法。在计算破折号的位置时,会说

位置

  1. 将索引设置为(索引+ 1)mod计数。
  2. 让短划线长度为最小值(短划线 index ,路径长度-位置)。
  3. 如果索引mod 2 = 0,则将位置添加到位置。
  4. 将位置设置为位置+长度。

不。 2表示,最后一个破折号总是在路径的前面或结尾结束,并且永远不会过冲。作为一种算法,这很有意义。但是规范还指出,每个破折号的开始和结束都由stroke-linecap定义的顶盖形状。

  1. 让位置作为子路径的破折号。

  2. 对于每对在以下位置:(...)

    1. 将破折号设置为破折号与位置开始处子路径的起始帽形的并集。

    2. 将破折号设置为破折号与位置末尾子路径的端帽形状的并集。

    3. 让索引和最后一个为子路径中沿子路径起点和终点的路径段的索引。

    4. 索引为

      1. 将dash设置为dash的并集,并将其设为段索引index处子路径的直线连接形状。
      2. 将索引设置为索引+ 1。

在特殊情况下,它没有提到闭合路径的开始和结束。 Linejoin的形状仅在虚线内 绘制,但始终在其末端绘制 cap 形状,从不绘制 join 形状。 >

这将回答者引向this question来建议stroke-linecap: square的用法。只要路径的第一段和最后一段相交垂直,此方法就可以很好地工作。但是,如果还有其他角度(如字母K和W一样),您仍然会得到不正确的结果。值round看起来很平滑,但也不同于其他线连接上的斜接效果。

path {
    fill: none;
    stroke: black;
    stroke-width: 20;
    stroke-dasharray: 250;
    stroke-linecap: square;
}
.smoothed {
   stroke-linecap: round;
}
<svg viewBox="0 0 300 100">
    <path d="M20 20 H 80 V 80 H 20 z" />
    <path d="M120 20 H 180 V 80 H 140 z" />
    <path d="M220 20 H 280 V 80 H 240 z" class="smoothed" />
</svg>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-