- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在尝试使用 Java 字符串操作来解析 VML 路径值。我想检索路径中的所有命令,例如 MoveTo、LineTo、CurveTo、RLineTo (其他命令)及其相应的 x 和 y 坐标/参数。
以下是要解析的示例数据,每个命令都有自己的 x,y 坐标。
1. m1,1 l1,200,200,200,200,1 xe
2. m, l1,200,200,200,200,1 xe
您能否建议一种用于检索命令和每个命令的参数的算法或代码?例如数字 1。
Command = moveto 'm'
Command Parameters = (x=1,y=1).
引用: http://www.w3.org/TR/NOTE-VML#_Toc416858391
这很奇怪,但我尝试使用 StringTokenizer 像
StringTokenizer tokenizer = new StringTokenizer(path);
一位 friend 建议使用 StringTokenizer,它的作用接近我的目标,它给了我以下数据。也许我可以利用 StringTokenizer 来满足我的需求。
m1,1
l1,200,200,200,200,1
xe
对于#1,这是理想的输出。 (伪代码)
String command_type = "m" List<String, String> parameters = add("1", "1")
String command_type = "l" List<String, String> parameters = add("1", "200")
add("200", "200")
add("200", "1")
String command_type = "x" (can have no parameter )
String command_type = "e" (can have no parameter )
对于#2,这是理想的输出。 (伪代码)
String command_type = "m" List<String, String> parameters = add("0", "0") // because the x and y parameters are not specified so I need to force them to 0,0
String command_type = "l" List<String, String> parameters = add("1", "200")
add("200", "200")
add("200", "1")
String command_type = "x" (can have no parameter )
String command_type = "e" (can have no parameter )
最佳答案
良好的规范在这里很重要,但根据您的示例输入和输出,我猜测:
字母 -> 逗号分隔参数 -> 字母 -> 逗号分隔参数
我还注意到命令不是用空格分隔的。例如你有 xe 作为两个单独的命令。这意味着在您的示例空间中没有任何意义,可以忽略。
我还注意到命令都是单个字母。 (否则 xe 不会作为两个命令出现)
此外参数必须成对出现并且必须是数字。我在你的样本中没有看到负数,但我认为这些是可能的。我还将假设它们是整数而不是小数。
因此,根据假定的规范,我可以提出一个可能的解决方案,供您查看并弄清楚它在做什么。
package ic.ac.uk.relationshipvisualiser.app;
import java.util.ArrayList;
import java.util.List;
public class TmpNoFXTest {
private static class coOrd {
int x = 0;
int y = 0;
public coOrd(int p_x,int p_y) {
x=p_x;y=p_y;
}
public int getX() {return x;}
public int getY() {return y;}
}
private static class command {
String command = "";
List<coOrd> param_list = new ArrayList<coOrd>();
public command(String p_command) {
command = p_command;
}
private String parseOneParam(String p_inp) {
if (p_inp.equals("")) return "";
if (isLetter(p_inp.substring(0,1))) return p_inp;
int firstChar = 0;
for (int c=0;c<p_inp.length();c++) {
if (firstChar==0) {
if (isLetter(p_inp.substring(c,c+1))) {
firstChar = c;
}
}
}
String parms = p_inp.substring(0,firstChar);
if (parms.length()==0) return p_inp.substring(firstChar);
int x = 0;
int y = 0;
int p = 0;
String tmp = "";
while ((p<parms.length()) && (!parms.substring(p,p+1).equals(","))) {
tmp = tmp + parms.substring(p,p+1);
p++;
}
p++;
if (tmp.length()>0) {
x = Integer.parseInt(tmp);
}
tmp = "";
while ((p<parms.length()) && (!parms.substring(p,p+1).equals(","))) {
tmp = tmp + parms.substring(p,p+1);
p++;
}
if (p_inp.substring(p,p+1)==",") p++;
if (tmp.length()>0) {
y = Integer.parseInt(tmp);
}
param_list.add(new coOrd(x,y));
return p_inp.substring(p);
}
public String parseParams(String p_inp) {
if (p_inp.equals("")) return "";
while (!isLetter(p_inp)) {
p_inp = parseOneParam(p_inp);
}
return p_inp;
}
public String toString() {
String ret = "";
ret = "String command_type = \"" + command + "\"";
if (param_list.size()==0) return ret + " (can have no parameter )";
for (int c=0;c<param_list.size();c++) {
if (c>0) ret += "\n ";
ret += " List<String, String> parameters = add(\"" + param_list.get(c).getX() + "\", \"" + param_list.get(c).getY() + "\")";
}
return ret;
}
}
private static boolean isLetter(String p_inp) {
return p_inp.substring(0,1).matches("\\p{L}");
}
private static String parseSingleCommand(String p_inp, List<command> p_cmds) throws Exception {
//Read a single command off the incoming string and pass the remaining input back
String cmd = p_inp.substring(0,1);
if (!isLetter(p_inp)) throw new Exception("Error command starts with non letter (" + cmd + ")");
p_inp = p_inp.substring(1);
command c = new command(cmd);
p_inp = c.parseParams(p_inp);
p_cmds.add(c);
return p_inp;
}
private static List<command> parse(String p_inp) throws Exception {
List<command> r = new ArrayList<command>();
//spaces don't matter and I want to make this case-insensitive to minimise errors
p_inp = p_inp.toLowerCase();
p_inp = p_inp.replace(" ", "");
while (p_inp.length()>0) {
p_inp = parseSingleCommand(p_inp,r);
}
return r;
}
public static void main(String[] args) {
System.out.println("Start tmpTest");
List<String> tests = new ArrayList<String>();
tests.add("m1,1 l1,200,200,200,200,1 xe");
tests.add("m, l1,200,200,200,200,1 xe");
for (int c=0;c<tests.size();c++) {
System.out.println("Running test case " + c + " (" + tests.get(c) + ")");
try {
List<command> pr = parse(tests.get(c));
for (int d=0;d<pr.size();d++) {
System.out.println(pr.get(d).toString());
}
} catch (Exception e) {
e.printStackTrace();
return;
}
};
System.out.println("End tmpTest");
}
}
关于java - VML 路径的字符串操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24140101/
我正在尝试在 VML 中创建一个与 clip-path 相对应的剪贴蒙版在 SVG 中?那可能吗? 基于大量但相当有限的示例,我尝试绘制形状:
您好,我正在尝试使用 Java 字符串操作来解析 VML 路径值。我想检索路径中的所有命令,例如 MoveTo、LineTo、CurveTo、RLineTo (其他命令)及其相应的 x 和 y 坐标/
我想在 IE 中使用 VML 绘制形状。我想出了以下代码,但它在 IE8 中没有显示任何内容。 Untitled Document v\: * { behavior:url(#default#
我为 Outlook 2007 使用 html 签名。签名包含一些图像文件。我想要嵌入图像文件,所以它不应该在附件中。但是 v:image 不显示图像。
我一直在寻找一种从 VML 文档中获取位图的方法。事实上,我正在处理一些使用标签的库,所以除了 IE(当然)我没有任何问题,因为我在 IE 中使用 ExCanvas,但我想从生成的“ Canvas ”
我现在正在学习 VML。我注意到每个示例都包含两个样式定义,如下所示: v\:* { behavior: url(#default#VML);} o\:* { beha
我已经设法使用 VML 为 td 显示背景图像,但我希望它垂直重复。我发现的任何例子都只适用于一张图片。谁能想到我能做到这一点?我已将我的示例页面放在下面的 fiddle 中。 http://jsfi
我正在使用 Raphael 渲染一些文本。 我希望能够单击并将此文本拖动到不同的容器中...例如...地址栏...使用 IE7。 最终我会将我自己的数据添加到 dataTransfer 对象,但只是让
我正在设计一个包含 VML 元素的新闻稿模板,我想知道是否可以将 TextBox 元素内的文本设置为不同的颜色以及设置所述文本的位置? 我目前正在使用以下 VML: 文本已向下移动,但我需要它向下移
我希望能够在以标准模式而不是怪异模式呈现的页面上使用 vml 对象。我发现了散落在各处的答案片段,但无法弄清楚。 Raphael以某种方式将它拉下来,但我无法扭转它以弄清楚发生了什么。任何基本的工作示
我有兴趣找到一个浏览器兼容性表,该表列出了每个版本的 Opera、Safari、Chrome、Firefox 和 Internet Explorer(Konqueror 也不错)支持的 SVG/VML
是否可以使用 vml v:rect 和 v:fill 技术嵌套背景图像?似乎嵌套的 v:fill 也会尝试填充第一个声明的 v:rect,这完全弄乱了我的布局 我正在尝试实现的示例(使用基金会的 in
例如: Hi Hey 当我使用这个标记时,我看不到内部圆角的背景。 有什么想法吗? 最佳答案 VML 形状不能相互嵌套。您需要对它们进行定位,以便它们正确重叠。
忽略浏览器支持问题(IE6、IE7 和 IE8 仅支持 VML;IE9 支持部分 SVG;其他主要浏览器支持 SVG)和弃用 VML 支持 SVG,SVG 和 VML 有多相似?我知道它们不兼容,但它
我有一个 SVG 文件,我想在 Internet Explorer 中查看它。 IE 将 VML 用于矢量文件,但我在任何地方都找不到这两种格式之间的任何类型的转换器! (不在 Inkscape、Il
我正在使用 VML 代码在 HTML 邮件中显示背景。我在一个表格单元格中有 3 个表格,它们并排放置,但是当我在 Outlook 中测试我的电子邮件时,表格不再彼此相邻,它使我的三个表格垂直对齐,就
我正在开展一个项目,该项目使用 Raphael 为 Chrome、Firefox 和 Safari 呈现 SVG,并为 Internet Explorer 呈现 VML。 由于 Raphael 没有对
在过去的两天里,我有效地弄清楚了如何不旋转 Raphael Elements。 基本上我正在尝试在元素上实现多个枢轴点以通过鼠标旋转它。 当用户进入旋转模式时,将创建 5 个枢轴。一个用于边界框的每个
我需要转换一个包含大量 VML 代码的大型应用程序。这个VML代码需要转换成SVG才能在IE10上流畅运行。 我见过很多将 SVG 转换成 VML 的库,但不是相反。那么,是否有人遇到过执行此过程的工
我在上一篇文章中发现了以下内容,但需要一些帮助: // For VML detection, here's what google maps does (search for "function Xd
我是一名优秀的程序员,十分优秀!