SVG在Firefox中无法正确呈现(SVG Not Rendering Correctly in Firefox)
我正在为一个项目开发SVG徽标,并且在测试时,徽标在Google Chrome中呈现正常,但在Firefox中无法正常呈现。
我用于SVG的代码是:
<svg version="1.1" id="svg-logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect id="svg-logo-rectangle" x="3.744" y="47.804" /> <text id="svg-logo-text-crocker" transform="matrix(1 0 0 1 130 98.3037)">Crocker</text> <text id="svg-logo-text-estates" transform="matrix(1 0 0 1 130 163.3037)" font-size="64.9214">Estates</text> <text id="svg-logo-text-c" transform="matrix(1 0 0 1 0 118.3037)">C</text> <text id="svg-logo-text-e" transform="matrix(1 0 0 1 55 168.3037)">E</text> <text id="svg-logo-text-house-finder" transform="matrix(1 0 0 1 131 197.3037)">House Finder</text> <g id="svg-logo-house-1"> <rect x="5.181" y="15.696" width="26.502" height="26.502"/> <polygon points="5.181,15.696 18.393,2.696 31.604,15.696 "/> <rect class="window" x="7.559" y="18.737" /> <rect class="window" x="21.684" y="18.737" /> <rect class="window" x="21.684" y="31.862" /> <rect class="door" x="8.871" y="36.011" width="4.875" height="6.703"/> </g> <g id="svg-logo-house-2"> <rect x="46.493" y="15.696" width="26.502" height="26.502"/> <polygon points="46.493,15.696 59.705,2.696 72.916,15.696 "/> <rect class="window" x="48.871" y="18.737" /> <rect class="window" x="62.996" y="18.737" /> <rect class="window" x="62.996" y="31.862" /> <rect class="door" x="50.184" y="36.011" width="4.875" height="6.703"/> </g> <g id="svg-logo-house-3"> <rect x="87.806" y="15.696" width="26.502" height="26.502"/> <polygon points="87.806,15.696 101.018,2.696 114.229,15.696 "/> <rect class="window" class="window" x="90.184" y="18.737" width="7.5" height="7.5"/> <rect class="window" class="window" x="104.309" y="18.737" width="7.5" height="7.5"/> <rect class="window" class="window" x="104.309" y="31.862" width="7.5" height="7.5"/> <rect class="door" x="91.496" y="36.011" /> </g> </svg>
你知道为什么这不起作用吗?
I am developing a SVG logo for a project, and, when testing it, the logo renders fine in Google Chrome, but doesn't render properly in Firefox.
The logo in Google Chrome, as it should look is:
The code I have used for the SVG is:
<svg version="1.1" id="svg-logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect id="svg-logo-rectangle" x="3.744" y="47.804" /> <text id="svg-logo-text-crocker" transform="matrix(1 0 0 1 130 98.3037)">Crocker</text> <text id="svg-logo-text-estates" transform="matrix(1 0 0 1 130 163.3037)" font-size="64.9214">Estates</text> <text id="svg-logo-text-c" transform="matrix(1 0 0 1 0 118.3037)">C</text> <text id="svg-logo-text-e" transform="matrix(1 0 0 1 55 168.3037)">E</text> <text id="svg-logo-text-house-finder" transform="matrix(1 0 0 1 131 197.3037)">House Finder</text> <g id="svg-logo-house-1"> <rect x="5.181" y="15.696" width="26.502" height="26.502"/> <polygon points="5.181,15.696 18.393,2.696 31.604,15.696 "/> <rect class="window" x="7.559" y="18.737" /> <rect class="window" x="21.684" y="18.737" /> <rect class="window" x="21.684" y="31.862" /> <rect class="door" x="8.871" y="36.011" width="4.875" height="6.703"/> </g> <g id="svg-logo-house-2"> <rect x="46.493" y="15.696" width="26.502" height="26.502"/> <polygon points="46.493,15.696 59.705,2.696 72.916,15.696 "/> <rect class="window" x="48.871" y="18.737" /> <rect class="window" x="62.996" y="18.737" /> <rect class="window" x="62.996" y="31.862" /> <rect class="door" x="50.184" y="36.011" width="4.875" height="6.703"/> </g> <g id="svg-logo-house-3"> <rect x="87.806" y="15.696" width="26.502" height="26.502"/> <polygon points="87.806,15.696 101.018,2.696 114.229,15.696 "/> <rect class="window" class="window" x="90.184" y="18.737" width="7.5" height="7.5"/> <rect class="window" class="window" x="104.309" y="18.737" width="7.5" height="7.5"/> <rect class="window" class="window" x="104.309" y="31.862" width="7.5" height="7.5"/> <rect class="door" x="91.496" y="36.011" /> </g> </svg>
Do you have any idea why this doesn't work?
原文:https://stackoverflow.com/questions/41590038
最满意答案
根据您指出的文章,这就是原因:
易失性写入比非易失性写入要昂贵得多,因为保证可见性所需的内存防护但通常比锁定获取更便宜。
[...]易失性读取很便宜 - 几乎和非易失性读取一样便宜
当然,这是正确的:无论底层变量是否为易失性,内存围栏操作总是以写入和读取的方式执行。
但是,Java中的volatile不仅仅是易失性和非易失性内存读取。 事实上,它本质上与这种区别无关:区别在于并发语义 。
考虑这个臭名昭着的例子:
volatile boolean runningFlag = true; void run() { while (runningFlag) { do work; } }
如果
runningFlag
不是volatile
,那么JIT编译器基本上可以重写该代码void run() { if (runningFlag) while (true) { do work; } }
不用说,通过读取每次迭代的
runningFlag
而不是完全读取它所引入的开销比率是巨大的。Here's why, according to the article you have indicated:
Volatile writes are considerably more expensive than nonvolatile writes because of the memory fencing required to guarantee visibility but still generally cheaper than lock acquisition.
[...] volatile reads are cheap -- nearly as cheap as nonvolatile reads
And that is, of course, true: memory fence operations are always bound to writing and reads execute the same way regardless of whether the underlying variable is volatile or not.
However,
volatile
in Java is about much more than just volatile vs. nonvolatile memory read. In fact, in its essence it has nothing to do with that distinction: the difference is in the concurrent semantics.Consider this notorious example:
volatile boolean runningFlag = true; void run() { while (runningFlag) { do work; } }
If
runningFlag
wasn'tvolatile
, the JIT compiler could essentially rewrite that code tovoid run() { if (runningFlag) while (true) { do work; } }
The ratio of overhead introduced by reading the
runningFlag
on each iteration against not reading it at all is, needless to say, enormous.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
是的,保证线程2将打印“完成”。 当然,如果在线程1中写入b实际上是在线程2中从b读取之前发生的,而不是在同一时间或更早的时间发生! 这里推理的核心是发生之前的关系 。 多线程程序执行被视为由事件组成。 事件可以通过发生之前的关系相关联,这表示一个事件发生在另一个事件之前。 即使两个事件不是直接相关的,如果你可以跟踪从一个事件到另一个事件之间的一连串发生关系,那么你可以说一个发生在另一个事件之前。 在您的情况下,您有以下事件: 线程1写入s 线程1写入b 线程2从b读取 线程2从s读取 以下规则发挥作用: ...
-
根据您指出的文章,这就是原因: 易失性写入比非易失性写入要昂贵得多,因为保证可见性所需的内存防护但通常比锁定获取更便宜。 [...]易失性读取很便宜 - 几乎和非易失性读取一样便宜 当然,这是正确的:无论底层变量是否为易失性,内存围栏操作总是以写入和读取的方式执行。 但是,Java中的volatile不仅仅是易失性和非易失性内存读取。 事实上,它本质上与这种区别无关:区别在于并发语义 。 考虑这个臭名昭着的例子: volatile boolean runningFlag = true; void run( ...
-
int* volatile仅表示指针本身是volatile 。 指向的数据不是volatile限定的,这意味着以下场景可能会导致优化程序错误: int a=10; int* volatile ptr=&a; int main() { for(;;) { printf("%d\n", *ptr); } } void some_ISR (void) { a = something; } 编译器小心不要假设ptr在循环中的每一圈都没有指向同一个地址,但除此之外它可以自由地假设:“啊哈 ...
-
写入引用类型(即Object )和字大小的值类型(即32位系统中的int )是原子的。 这意味着当你查看值(位置6)时,你可以确定你得到的是旧值或新值,但不是别的(如果你有一个像大型结构这样的类型,它可以被拼接,你可以在写作过程中读取价值)。 只要您愿意接受阅读陈旧价值的潜在风险,您就不需要 lock或volatile 。 请注意,由于在此处没有引入内存屏障(一个lock或使用volatile添加一个),所以可能该变量已在另一个线程中更新,但当前线程没有观察到该更改; 它可能会在另一个线程中更改(可能)一段 ...
-
根据JMM,以下顺序严格按照先发生关系排序,因此保证了步骤1中读者在步骤4完成的更改的可见性: 写入x 从监视器M保护的同步块退出 进入由监视器M保护的同步块 从x读取 写入变量发生 - 在释放监视器之前,释放监视器 - 在获取相同的监视器并获取监视器发生之前 - 在从变量读取之前。 所以如果p和v是同步的,那么线程0会看到x的变化。 According to JMM the following sequence is strictly ordered by happens-before relations ...
-
我的问题是,是否需要担心由于优化或其他线程缓存而导致静态_cachedResult仍然被其他线程视为null。 是的你是。 这是volatile存在的主要原因之一。 值得一提的是,无争议的锁定会增加一个完全可以忽略的性能成本,所以没有理由只是lock空检查和资源生成,因为它几乎肯定不会导致任何性能问题,并且使程序更容易关于的原因。 最好的解决方案是完全避免这个问题,并使用专门设计来解决您的确切问题的更高级别的抽象。 在这种情况下,这意味着Lazy 。 您可以创建一个Lazy对象,该对象定义了如何创建昂贵的资 ...
-
volatile确保访问对其他内核可见, Interlocked也是如此。 与互锁的区别在于它使用完整的内存屏障来保证并处理非原子操作。 易失性可能不会使用完整的内存屏障(取决于平台,例如x86 / x64不需要带有volatile的完整内存屏障......)但只能使原子操作“线程安全”。 通常建议避免使用volatile,因为它会使对该变量的每次原子访问都“易变”(这对x86 / x64来说可能不是那么大)并且有点隐藏了对变量的访问不同的事实。 通常更推荐使用Interlocked东西,因为它明确详细说明 ...
-
从N个线程同时读取/写入(不销毁,不创建)“Q”元素是否安全? 不,不是。 看下一个情况。 Thread 1 Thread 2 qs.add(queue1); qs.delete(queue1); ... ... qs.add(queue100); qs.delete(queue100); 您同时添加并将对象删除到非同步 List 。 如果我们假设你们都尝试删除并添加到列表对象中,则会得到ConcurrentModific ...