- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
CSS Exclusions似乎完全符合我的要求,但支持相当少(目前只有 IE10+...)。
知道如何在 JS 中解决这个问题吗?可以是服务器端或客户端。甚至可以是 PHP 或 Python 或其他任何东西。
谢谢
最佳答案
在 canvas 上玩了一下,想出了这个:
var canvas = document.body.appendChild(document.createElement("canvas"));
canvas.width = 200;
canvas.height = canvas.width;
var ctx = canvas.getContext("2d");
var Shape = (function() {
function Shape(position, points) {
if (points === void 0) {
points = [];
}
this.position = position;
this.points = points;
}
Shape.prototype.draw = function(ctx, str) {
var lineSize = ctx.measureText("a").width;
var minY = this.points
.map(function(a) {
return a.y;
})
.sort(function(a, b) {
return (a < b ? -1 : 1);
})[0];
var minX = this.points
.map(function(a) {
return a.x;
})
.sort(function(a, b) {
return (a < b ? -1 : 1);
})[0];
var maxY = this.points
.map(function(a) {
return a.y;
})
.sort(function(a, b) {
return (b < a ? -1 : 1);
})[0];
var maxX = this.points
.map(function(a) {
return a.x;
})
.sort(function(a, b) {
return (b < a ? -1 : 1);
})[0];
ctx.fillStyle = "rgba(255,0,0,0.1)";
for (var ai = 0; ai < this.points.length; ai++) {
var a = this.points[ai];
var b = this.points[(ai + 1) % this.points.length];
if (ai === 0) {
ctx.beginPath();
ctx.moveTo(a.x + this.position.x, a.y + this.position.y);
}
ctx.lineTo(b.x + this.position.x, b.y + this.position.y);
}
ctx.closePath();
ctx.fill();
//ctx.textBaseline = "bottom";
ctx.fillStyle = "black";
var strLeft = str;
var line = minY;
while (line <= maxY && strLeft.length > 0) {
var startX = null;
var endX = null;
for (var x = minX; x <= maxX; x += lineSize) {
var data = ctx.getImageData(x + this.position.x - lineSize, line + this.position.y - lineSize, 1, 1).data;
if (data[0] + data[1] + data[2] + data[3] > 0) {
if (startX === null) {
startX = x;
} else {
endX = x;
}
}
}
var length = Math.floor((endX - startX) / lineSize);
var localStr = strLeft.substr(0, length);
strLeft = strLeft.substr(length);
ctx.fillText(localStr, startX + this.position.x, line + this.position.y);
line += lineSize + 2;
}
};
return Shape;
}());
var shape = new Shape({
x: 100,
y: 60
}, [{
x: -100,
y: -40
},
{
x: 100,
y: -60
},
{
x: 0,
y: 0
},
]);
shape.draw(ctx, "once upon a midnight dreary while i pondered weak and weary");
这很粗糙,但这是一个起点。
编辑
这是一个更贴切的描述,使用了具有不变符号大小的字体:
var canvas = document.body.appendChild(document.createElement("canvas"));
canvas.width = 610;
canvas.height = 787;
var ctx = canvas.getContext("2d");
var bgimg = (function() {
var img = document.createElement("img");
img.src = '/image/XYThp.png';
return img;
})();
canvas.onclick = function(evt) {
console.log(evt.layerX - evt.target.offsetLeft, evt.layerY);
};
var Shape = (function() {
function Shape(position, points) {
if (points === void 0) {
points = [];
}
this.position = position;
this.points = points;
}
Shape.prototype.draw = function(ctx, str) {
ctx.font = "14px Courier";
var lineSize = ctx.measureText("i").width;
var minY = this.points
.map(function(a) {
return a.y;
})
.sort(function(a, b) {
return (a < b ? -1 : 1);
})[0];
var minX = this.points
.map(function(a) {
return a.x;
})
.sort(function(a, b) {
return (a < b ? -1 : 1);
})[0];
var maxY = this.points
.map(function(a) {
return a.y;
})
.sort(function(a, b) {
return (b < a ? -1 : 1);
})[0];
var maxX = this.points
.map(function(a) {
return a.x;
})
.sort(function(a, b) {
return (b < a ? -1 : 1);
})[0];
ctx.fillStyle = "rgba(255,0,0,0.1)";
for (var ai = 0; ai < this.points.length; ai++) {
var a = this.points[ai];
var b = this.points[(ai + 1) % this.points.length];
if (ai === 0) {
ctx.beginPath();
ctx.moveTo(a.x + this.position.x, a.y + this.position.y);
}
ctx.lineTo(b.x + this.position.x, b.y + this.position.y);
}
ctx.closePath();
ctx.fill();
//ctx.textBaseline = "bottom";
ctx.fillStyle = "black";
var strLeft = str;
var line = minY;
while (line <= maxY && strLeft.length > 0) {
var startX = null;
var endX = null;
for (var x = minX; x <= maxX; x += lineSize) {
var data = ctx.getImageData(x + this.position.x, line + this.position.y, 1, 1).data;
if (data[0] + data[1] + data[2] + data[3] > 0) {
if (startX === null) {
startX = x;
} else {
endX = x;
}
}
}
if (line == 398) {
console.log(startX, endX);
}
var length = Math.floor((endX - startX) / lineSize);
var localStr = strLeft.substr(0, length);
strLeft = strLeft.substr(length);
ctx.fillText(localStr, startX + this.position.x, line + this.position.y);
line += lineSize + 2;
}
/*
ctx.globalCompositeOperation = 'destination-over';
ctx.drawImage(bgimg, 0, 0);
ctx.globalCompositeOperation = 'source-over';
*/
};
return Shape;
}());
var shape = new Shape({
x: 0,
y: 0
}, [{
x: 5,
y: 104
},
{
x: 125,
y: 46
},
{
x: 205,
y: 50
},
{
x: 254,
y: 101
},
{
x: 346,
y: 180
},
{
x: 398,
y: 254
},
{
x: 425,
y: 290
},
{
x: 462,
y: 347
},
{
x: 476,
y: 414
},
{
x: 485,
y: 459
},
{
x: 515,
y: 546
},
{
x: 524,
y: 590
},
{
x: 539,
y: 634
},
{
x: 572,
y: 689
},
{
x: 571,
y: 712
},
{
x: 567,
y: 734
},
{
x: 582,
y: 777
},
{
x: 557,
y: 746
},
{
x: 492,
y: 744
},
{
x: 489,
y: 757
},
{
x: 461,
y: 757
},
{
x: 349,
y: 597
},
{
x: 203,
y: 537
},
{
x: 130,
y: 413
},
{
x: 94,
y: 312
},
{
x: 93,
y: 244
},
{
x: 103,
y: 198
},
{
x: 105,
y: 162
},
{
x: 73,
y: 124
},
{
x: 36,
y: 118
},
]);
setTimeout(function() {
shape.draw(ctx, "Once upon a midnight dreary, while I pondered, weak and weary,\nOver many a quaint and curious volume of forgotten lore\u2014\nWhile I nodded, nearly napping, suddenly there came a tapping,\nAs of some one gently rapping, rapping at my chamber door.\n\u201C\u2019Tis some visitor,\u201D I muttered, \u201Ctapping at my chamber door\u2014\nOnly this and nothing more.\u201D\n\nAh, distinctly I remember it was in the bleak December;\nAnd each separate dying ember wrought its ghost upon the floor.\nEagerly I wished the morrow;\u2014vainly I had sought to borrow\nFrom my books surcease of sorrow\u2014sorrow for the lost Lenore\u2014\nFor the rare and radiant maiden whom the angels name Lenore\u2014\nNameless here for evermore.\n\nAnd the silken, sad, uncertain rustling of each purple curtain\nThrilled me\u2014filled me with fantastic terrors never felt before;\nSo that now, to still the beating of my heart, I stood repeating\n\u201C\u2019Tis some visitor entreating entrance at my chamber door\u2014\nSome late visitor entreating entrance at my chamber door;\u2014\nThis it is and nothing more.\u201D\n\nPresently my soul grew stronger; hesitating then no longer,\n\u201CSir,\u201D said I, \u201Cor Madam, truly your forgiveness I implore;\nBut the fact is I was napping, and so gently you came rapping,\nAnd so faintly you came tapping, tapping at my chamber door,\nThat I scarce was sure I heard you\u201D\u2014here I opened wide the door;\u2014\nDarkness there and nothing more.\n\nDeep into that darkness peering, long I stood there wondering, fearing,\nDoubting, dreaming dreams no mortal ever dared to dream before;\nBut the silence was unbroken, and the stillness gave no token,\nAnd the only word there spoken was the whispered word, \u201CLenore?\u201D\nThis I whispered, and an echo murmured back the word, \u201CLenore!\u201D\u2014\nMerely this and nothing more.\n\nBack into the chamber turning, all my soul within me burning,\nSoon again I heard a tapping somewhat louder than before.\n\u201CSurely,\u201D said I, \u201Csurely that is something at my window lattice;\nLet me see, then, what thereat is, and this mystery explore\u2014\nLet my heart be still a moment and this mystery explore;\u2014\n\u2019Tis the wind and nothing more!\u201D\n\nOpen here I flung the shutter, when, with many a flirt and flutter,\nIn there stepped a stately Raven of the saintly days of yore;\nNot the least obeisance made he; not a minute stopped or stayed he;\nBut, with mien of lord or lady, perched above my chamber door\u2014\nPerched upon a bust of Pallas just above my chamber door\u2014\nPerched, and sat, and nothing more.\n\nThen this ebony bird beguiling my sad fancy into smiling,\nBy the grave and stern decorum of the countenance it wore,\n\u201CThough thy crest be shorn and shaven, thou,\u201D I said, \u201Cart sure no craven,\nGhastly grim and ancient Raven wandering from the Nightly shore\u2014\nTell me what thy lordly name is on the Night\u2019s Plutonian shore!\u201D\nQuoth the Raven \u201CNevermore.\u201D\n\nMuch I marvelled this ungainly fowl to hear discourse so plainly,\nThough its answer little meaning\u2014little relevancy bore;\nFor we cannot help agreeing that no living human being\nEver yet was blessed with seeing bird above his chamber door\u2014\nBird or beast upon the sculptured bust above his chamber door,\nWith such name as \u201CNevermore.\u201D\n\nBut the Raven, sitting lonely on the placid bust, spoke only\nThat one word, as if his soul in that one word he did outpour.\nNothing farther then he uttered\u2014not a feather then he fluttered\u2014\nTill I scarcely more than muttered \u201COther friends have flown before\u2014\nOn the morrow he will leave me, as my Hopes have flown before.\u201D\nThen the bird said \u201CNevermore.\u201D\n\nStartled at the stillness broken by reply so aptly spoken,\n\u201CDoubtless,\u201D said I, \u201Cwhat it utters is its only stock and store\nCaught from some unhappy master whom unmerciful Disaster\nFollowed fast and followed faster till his songs one burden bore\u2014\nTill the dirges of his Hope that melancholy burden bore\nOf \u2018Never\u2014nevermore\u2019.\u201D\n\nBut the Raven still beguiling all my fancy into smiling,\nStraight I wheeled a cushioned seat in front of bird, and bust and door;\nThen, upon the velvet sinking, I betook myself to linking\nFancy unto fancy, thinking what this ominous bird of yore\u2014\nWhat this grim, ungainly, ghastly, gaunt, and ominous bird of yore\nMeant in croaking \u201CNevermore.\u201D\n\nThis I sat engaged in guessing, but no syllable expressing\nTo the fowl whose fiery eyes now burned into my bosom\u2019s core;\nThis and more I sat divining, with my head at ease reclining\nOn the cushion\u2019s velvet lining that the lamp-light gloated o\u2019er,\nBut whose velvet-violet lining with the lamp-light gloating o\u2019er,\nShe shall press, ah, nevermore!\n\nThen, methought, the air grew denser, perfumed from an unseen censer\nSwung by Seraphim whose foot-falls tinkled on the tufted floor.\n\u201CWretch,\u201D I cried, \u201Cthy God hath lent thee\u2014by these angels he hath sent thee\nRespite\u2014respite and nepenthe from thy memories of Lenore;\nQuaff, oh quaff this kind nepenthe and forget this lost Lenore!\u201D\nQuoth the Raven \u201CNevermore.\u201D\n\n\u201CProphet!\u201D said I, \u201Cthing of evil!\u2014prophet still, if bird or devil!\u2014\nWhether Tempter sent, or whether tempest tossed thee here ashore,\nDesolate yet all undaunted, on this desert land enchanted\u2014\nOn this home by Horror haunted\u2014tell me truly, I implore\u2014\nIs there\u2014is there balm in Gilead?\u2014tell me\u2014tell me, I implore!\u201D\nQuoth the Raven \u201CNevermore.\u201D\n\n\u201CProphet!\u201D said I, \u201Cthing of evil!\u2014prophet still, if bird or devil!\nBy that Heaven that bends above us\u2014by that God we both adore\u2014\nTell this soul with sorrow laden if, within the distant Aidenn,\nIt shall clasp a sainted maiden whom the angels name Lenore\u2014\nClasp a rare and radiant maiden whom the angels name Lenore.\u201D\nQuoth the Raven \u201CNevermore.\u201D\n\n\u201CBe that word our sign of parting, bird or fiend!\u201D I shrieked, upstarting\u2014\n\u201CGet thee back into the tempest and the Night\u2019s Plutonian shore!\nLeave no black plume as a token of that lie thy soul hath spoken!\nLeave my loneliness unbroken!\u2014quit the bust above my door!\nTake thy beak from out my heart, and take thy form from off my door!\u201D\nQuoth the Raven \u201CNevermore.\u201D\n\nAnd the Raven, never flitting, still is sitting, still is sitting\nOn the pallid bust of Pallas just above my chamber door;\nAnd his eyes have all the seeming of a demon\u2019s that is dreaming,\nAnd the lamp-light o\u2019er him streaming throws his shadow on the floor;\nAnd my soul from out that shadow that lies floating on the floor\nShall be lifted\u2014nevermore!");
}, 100);
请注意,计算需要一些时间。
关于javascript - 用文本填充复杂的多边形 - CSS 排除的任何 JS(或其他)替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43652840/
我有一个名为 main.css 的 css 文件和另一个名为 style.css 的文件。我怎样才能在 main.css 中做到这一点? .someClass { //apply rules to
在更新我的 css 之前,我在 Login.css 中有以下内容: body { background-image: url('./pictures/fond.png'); bac
我的 share point 2013 核心 css 和我的 css 之间存在 css 冲突。所以我想把我所有的类都放在 div #s4-workspace 下但是我搜索了一种方法来将所有类分组到这个
我知道您可以覆盖 jsp 页面从 jsp 包含 CSS 文件(即全局 CSS 文件)继承的 CSS 属性。 但是,如果元素中的某个属性弄乱了特定页面,而我不想只使用内联 CSS 在该页面中使用它怎么办
我刚刚发现了 initial-scale 元属性。 以前,我一直在使用 default.css 来定义我所有的样式和大小(用于字体和元素),以便它们在桌面计算机的屏幕上显示得很好。然后,如果您使用的是
我正在尝试使用 LESS CSS 来编写我的 CSS。我已经按顺序导入了 style.less 和 less.js 文件。 现在我想提取 LESS 生成的 CSS。有什么办法可以做到吗?我不想使用脚本
我想知道是否有任何一种软件可以读取大量内联样式中的 HTML 文档并将所有这些样式转换为外部 css 文件。如果只有一页,我可以手动完成。但是有100页。有人有想法吗? 最佳答案 就像有人说的那样,“
当我想从 Styled Components 迁移到 CSS Modules 时,出现了以下问题。 假设我有以下样式组件,它接受动态参数 offset和一个动态 CSS 字符串 theme : con
有没有办法将 CSS 类定义为与另一个类相等?例如,如果我有一个类: .myClass{ background-color: blue; } 有没有一种方法可以将第二个类定义为与 myClas
我正在尝试制作一组按钮,这些按钮贴在页面底部并且由固定的空间隔开。我正在使用 angularJS 的 ng-repeat 指令通过 ajax 请求获取数据,然后我用它来显示按钮。 我的问题在于让按
浏览器是否在加载 CSS 文件时解析 CSS?还是在整个 CSS 文件被浏览器下载后才进行解析?不同浏览器的做法有区别吗?我在哪里可以找到这种底层信息? 这个问题不是 Load and executi
这个问题在这里已经有了答案: Can a CSS class inherit one or more other classes? (29 个答案) 关闭 3 年前。 标题有点乱,我给大家看一下。假
我遇到了最奇怪的问题...... 在最简单的形式中,我有一个包含以下内容的 index.html 文件: (在尝试确定根本原因的过程中,我已经大大减少了它) 当我查看页面的源代码时,我得到以下信息:
我正在使用 Mindscape Workbench 来最小化我的 scss 文件。我的页面设置为使用 *.min.css 文件。在随机时间,min 文件不会与系统的其余部分一起发布。 我有很多 css
请告诉我 CSS 框架和 CSS 网格之间的区别。 最佳答案 CSS 框架也可以是 CSS 网格框架。 CSS 网格框架用于构建 CSS 布局。有一些框架除了构建布局还有其他用途,例如 Hartija
我有无法从页面中删除或更改的 original.css 文件。原始.css table { border-collapse: collapse; border-spacing: 0;
我以前使用 bootstrap css import 很好。 但是我正在尝试使用 CSS 模块,所以我添加了几行。 { test: /\.css$/, use:
有没有办法在 css 选择器中创建一个 css 组。 例如: .SectionHeader { include: .foo; include: .bar; include: .
今天我学习了 CSS 中的两个概念,一个是 CSS 定位(静态、相对、绝对、固定),另一个是 CSS Margin,它定义了元素之间的空间。 假设我想移动一个元素,这是最好的方法吗?因为这两个概念似乎
var paths = { css: './public/apps/user/**/*.css' } var dest = { css: './public/apps/user/css/' } /
我是一名优秀的程序员,十分优秀!