Javascript 未在html5画布中呈现文本-IE7&;8(fabric.js)

Javascript 未在html5画布中呈现文本-IE7&;8(fabric.js),javascript,html,canvas,html5-canvas,fabricjs,Javascript,Html,Canvas,Html5 Canvas,Fabricjs,我正在使用canvas、Fabric.js库和IE canvas fix(excanvas.js)在图像上生成一些可编辑的曲线文本,但在IE7和IE8中,文本似乎根本无法渲染 这是使用canvas for IE7&8的文本的已知问题,还是我可以使用js修复程序来实现这一点 下面是使用此处的curvedText示例修改的代码: HTML和CSS <style type="text/css"> body{ font-family: Helvetica; font-weight: nor

我正在使用canvas、Fabric.js库和IE canvas fix(excanvas.js)在图像上生成一些可编辑的曲线文本,但在IE7和IE8中,文本似乎根本无法渲染

这是使用canvas for IE7&8的文本的已知问题,还是我可以使用js修复程序来实现这一点

下面是使用此处的curvedText示例修改的代码:

HTML和CSS

<style type="text/css">
body{
font-family: Helvetica;
font-weight: normal;
font-size: 13px;
}
.canvas-box{
clear: both;
position: relative;
width: 740px;
height: 700px;
margin: auto;
}
.canvas-box .canvas-nav{
width: 200px;
height: 462px;
float: left;
position: relative;
background: #E9E9E9;
padding: 20px;
}
.canvas-box .canvas-wrap{
float: left;
position: relative;
}
</style>

<div class="canvas-box">
<div class="canvas-wrap">
<canvas id="c" width="500" height="500" style="border:1px solid #E9E9E9;"></canvas><br/>
</div>
<div class="canvas-nav">
<input type="text" id="text" value="Enter Your Name" maxlength="20" /><br>
Radius : <input type="range"  min="0" max="100" value="50" id="radius" /><br>
Spacing : <input type="range"  min="5" max="40" value="20" id="spacing" /><br>
<button id="save_img">Save Image</button>
</div>
</div>
<div class="show_img"></div>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<!--[if IE]><script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script><![endif]-->
<script type='text/javascript' src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.2.0/fabric.all.min.js"></script>
<script type='text/javascript' src="https://rawgithub.com/EffEPi/fabric.curvedText/master/fabric.curvedText.js"></script>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
var CurvedTextWidth = 0;
canvas = new fabric.Canvas('c');
var circle = new fabric.Circle({
radius: 100, fill: 'blue', left: $("#c").width() / 2, top: $("#c").height() / 2, selectable: false
});
canvas.add(circle);
canvas.on('selection:cleared', onDeSelected);
canvas.on('object:selected', onSelected);
canvas.on('selection:created', onSelected);

var CurvedText = new fabric.CurvedText($('#text').val(),{
left: $("#c").width() / 2,
top: $("#c").height() / 2 -50,
textAlign: 'center',
fill: '#ffffff',
radius: 80,
id: 12,
fontSize: 18,
spacing: 10,
fontFamily: 'Arial',
fontWeight: 'normal'
});

canvas.add(CurvedText).renderAll(); 
canvas.setActiveObject(canvas.item(canvas.getObjects().length-1));
$('#text').keyup(function(){
var obj = canvas.getActiveObject();
if(obj){
obj.setText(this.value);
canvas.renderAll();
//update space and position
updatePos();
}
});

$('#text').focus(function(){
canvas.setActiveObject(canvas.item(canvas.getObjects().length-1));
});

//update space and position
function updatePos(){
CurvedText.top=$("#c").height() / 2 - 86 + CurvedText.height/2;
canvas.renderAll();
}

$('#radius, #spacing').change(function(){
var obj = canvas.getActiveObject();
if(obj){
obj.set($(this).attr('id'),$(this).val()); 
}
canvas.renderAll();
//update space and position
updatePos();
});

$('#radius, #spacing').change(function(){
var obj = canvas.getActiveObject();
if(obj){
obj.set($(this).attr('id'),$(this).val()); 
}
canvas.renderAll();
//update space and position
updatePos();
});

$('#convert').click(function(){
var props = {};
var obj = canvas.getActiveObject();
if(obj){
if(/curvedText/.test(obj.type)) {
default_text = obj.getText();
props = obj.toObject();
delete props['type'];
var textSample = new fabric.Text(default_text, props);
}else if(/text/.test(obj.type)) {
default_text = obj.getText();
props = obj.toObject();
delete props['type'];
props['textAlign'] = 'center';
props['radius'] = 50;
props['spacing'] = 20;
var textSample = new fabric.CurvedText(default_text, props);
}
canvas.remove(obj);
canvas.add(textSample).renderAll();
canvas.setActiveObject(canvas.item(canvas.getObjects().length-1));
}
});

function onSelected(){
var obj = canvas.getActiveObject();
$('#text').val(obj.getText());
$('#reverse').prop('checked', obj.get('reverse'));
$('#radius').val(obj.get('radius'));
$('#spacing').val(obj.get('spacing'));
$('#fill').val(obj.getFill());
}
function onDeSelected(){
$('#reverse').prop('checked', false);
$('#radius').val(50);
$('#spacing').val(20);
$('#fill').val('#0000FF');
}
});//]]>  

$("#save_img").click(function(){
canvas.deactivateAll().renderAll();
var mycanvas = document.getElementById("c"); //get your canvas
var image    = mycanvas.toDataURL("image/png");
window.open(image);
});
</script>

身体{
字体系列:Helvetica;
字体大小:正常;
字体大小:13px;
}
.帆布箱{
明确:两者皆有;
位置:相对位置;
宽度:740px;
高度:700px;
保证金:自动;
}
.帆布箱.帆布导航{
宽度:200px;
身高:462px;
浮动:左;
位置:相对位置;
背景:#E9E9E9;
填充:20px;
}
.帆布盒.帆布包装{
浮动:左;
位置:相对位置;
}


半径:
间距:
保存图像
JS

<style type="text/css">
body{
font-family: Helvetica;
font-weight: normal;
font-size: 13px;
}
.canvas-box{
clear: both;
position: relative;
width: 740px;
height: 700px;
margin: auto;
}
.canvas-box .canvas-nav{
width: 200px;
height: 462px;
float: left;
position: relative;
background: #E9E9E9;
padding: 20px;
}
.canvas-box .canvas-wrap{
float: left;
position: relative;
}
</style>

<div class="canvas-box">
<div class="canvas-wrap">
<canvas id="c" width="500" height="500" style="border:1px solid #E9E9E9;"></canvas><br/>
</div>
<div class="canvas-nav">
<input type="text" id="text" value="Enter Your Name" maxlength="20" /><br>
Radius : <input type="range"  min="0" max="100" value="50" id="radius" /><br>
Spacing : <input type="range"  min="5" max="40" value="20" id="spacing" /><br>
<button id="save_img">Save Image</button>
</div>
</div>
<div class="show_img"></div>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<!--[if IE]><script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script><![endif]-->
<script type='text/javascript' src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.2.0/fabric.all.min.js"></script>
<script type='text/javascript' src="https://rawgithub.com/EffEPi/fabric.curvedText/master/fabric.curvedText.js"></script>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
var CurvedTextWidth = 0;
canvas = new fabric.Canvas('c');
var circle = new fabric.Circle({
radius: 100, fill: 'blue', left: $("#c").width() / 2, top: $("#c").height() / 2, selectable: false
});
canvas.add(circle);
canvas.on('selection:cleared', onDeSelected);
canvas.on('object:selected', onSelected);
canvas.on('selection:created', onSelected);

var CurvedText = new fabric.CurvedText($('#text').val(),{
left: $("#c").width() / 2,
top: $("#c").height() / 2 -50,
textAlign: 'center',
fill: '#ffffff',
radius: 80,
id: 12,
fontSize: 18,
spacing: 10,
fontFamily: 'Arial',
fontWeight: 'normal'
});

canvas.add(CurvedText).renderAll(); 
canvas.setActiveObject(canvas.item(canvas.getObjects().length-1));
$('#text').keyup(function(){
var obj = canvas.getActiveObject();
if(obj){
obj.setText(this.value);
canvas.renderAll();
//update space and position
updatePos();
}
});

$('#text').focus(function(){
canvas.setActiveObject(canvas.item(canvas.getObjects().length-1));
});

//update space and position
function updatePos(){
CurvedText.top=$("#c").height() / 2 - 86 + CurvedText.height/2;
canvas.renderAll();
}

$('#radius, #spacing').change(function(){
var obj = canvas.getActiveObject();
if(obj){
obj.set($(this).attr('id'),$(this).val()); 
}
canvas.renderAll();
//update space and position
updatePos();
});

$('#radius, #spacing').change(function(){
var obj = canvas.getActiveObject();
if(obj){
obj.set($(this).attr('id'),$(this).val()); 
}
canvas.renderAll();
//update space and position
updatePos();
});

$('#convert').click(function(){
var props = {};
var obj = canvas.getActiveObject();
if(obj){
if(/curvedText/.test(obj.type)) {
default_text = obj.getText();
props = obj.toObject();
delete props['type'];
var textSample = new fabric.Text(default_text, props);
}else if(/text/.test(obj.type)) {
default_text = obj.getText();
props = obj.toObject();
delete props['type'];
props['textAlign'] = 'center';
props['radius'] = 50;
props['spacing'] = 20;
var textSample = new fabric.CurvedText(default_text, props);
}
canvas.remove(obj);
canvas.add(textSample).renderAll();
canvas.setActiveObject(canvas.item(canvas.getObjects().length-1));
}
});

function onSelected(){
var obj = canvas.getActiveObject();
$('#text').val(obj.getText());
$('#reverse').prop('checked', obj.get('reverse'));
$('#radius').val(obj.get('radius'));
$('#spacing').val(obj.get('spacing'));
$('#fill').val(obj.getFill());
}
function onDeSelected(){
$('#reverse').prop('checked', false);
$('#radius').val(50);
$('#spacing').val(20);
$('#fill').val('#0000FF');
}
});//]]>  

$("#save_img").click(function(){
canvas.deactivateAll().renderAll();
var mycanvas = document.getElementById("c"); //get your canvas
var image    = mycanvas.toDataURL("image/png");
window.open(image);
});
</script>

//  
$(“#保存img”)。单击(函数(){
canvas.deactivateAll().renderAll();
var mycanvas=document.getElementById(“c”);//获取画布
var image=mycanvas.toDataURL(“image/png”);
窗口。打开(图像);
});

对不起,伙计,你不能在IE7和ie8中使用画布。此处不支持画布Api


Dude use ExCanvas for IE8这是IE8浏览器中的唯一支持,而不是IE 7中的支持

本机画布文本支持需要IE9+。但也许你可以使用Cufon——不确定曲线文本是否适用于Cufon。