日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

html text width,HTML5 Text Canvas rotate in case text width is larger than maximum width allowed

發布時間:2024/9/27 HTML 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html text width,HTML5 Text Canvas rotate in case text width is larger than maximum width allowed 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題

Friends, i'm finding rotating a text canvas object a bit tricky. The thing is, I'm drawing a graphic, but sometimes the width of each bar is smaller than the 'value' of that bar. So I have to ratate the 'value' 90 degrees. It will work in most cases.

I am doing the following

a function(x, y, text, maxWidth...)

var context = this.element.getContext('2d');

var metric = context.measureText(text); //metric will receive the measures of the text

if(maxWidth != null){

if(metric.width > maxWidth) context.rotate(Math.PI / 2);

}

context.fillText(text, x, y);

Ok, but it doesn't really work. Problems that I have seen: The text duplicates in different angles. The angles are not what I want (perhaps just a matter of trigonometry).

Well I just don't know what to do. I read something about methods like 'save' and 'restore' but I don't what to do with them. I've made some attempts but no one worked.

Would you help me with this, guys?

回答1:

This is a bit tricky to answer simply because there are a lot of concepts going on, so I've made you an example of what I think you'd like to do here:

http://jsfiddle.net/5UKE3/

The main part of it is this. I've put in a lot of comments to explain whats going on:

function drawSomeText(x, y, text, maxWidth) {

//metric will receive the measures of the text

var metric = ctx.measureText(text);

console.log(metric.width);

ctx.save(); // this will "save" the normal canvas to return to

if(maxWidth != null && metric.width > maxWidth) {

// These two methods will change EVERYTHING

// drawn on the canvas from this point forward

// Since we only want them to apply to this one fillText,

// we use save and restore before and after

// We want to find the center of the text (or whatever point you want) and rotate about it

var tx = x + (metric.width/2);

var ty = y + 5;

// Translate to near the center to rotate about the center

ctx.translate(tx,ty);

// Then rotate...

ctx.rotate(Math.PI / 2);

// Then translate back to draw in the right place!

ctx.translate(-tx,-ty);

}

ctx.fillText(text, x, y);

ctx.restore(); // This will un-translate and un-rotate the canvas

}

To rotate around the right spot you have to translate to that spot, then rotate, then translate back.

Once you rotate the canvas the context is rotated forever, so in order to stop all your new drawing operations from rotating when you dont want them to, you have to use save and restore to "remember" the normal, unrotated context.

If anything else doesn't make sense let me know. Have a good time making canvas apps!

來源:https://stackoverflow.com/questions/7755050/html5-text-canvas-rotate-in-case-text-width-is-larger-than-maximum-width-allowed

總結

以上是生活随笔為你收集整理的html text width,HTML5 Text Canvas rotate in case text width is larger than maximum width allowed的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 中文在线日本 | 中文字幕 亚洲一区 | 亚洲视频一区二区三区在线观看 | 日日噜噜噜夜夜爽爽狠狠视频97 | 久久在线免费观看 | 国产视频123| 久久精品8 | 黑人乱码一区二区三区av | 好看的av网址 | 99久久久无码国产精品免费 | 免费观看一级一片 | 女人裸体免费网站 | 亚洲免费观看高清在线观看 | 亚洲国产精品成人综合色在线婷婷 | av巨作 | 在线看福利影 | 色牛影院 | 欧美大喷水吹潮合集在线观看 | 91免费 看片 | www色中色 | 欧美色图激情小说 | 成人av手机在线 | 无码人妻精品一区二区蜜桃网站 | 国产精品国产精品国产专区蜜臀ah | 黄色小视频国产 | 中文久久乱码一区二区 | 蜜臀av一区二区三区 | 日韩黄色一级片 | 国内视频精品 | 非洲黄色片| 欧美色拍| 在线免费三级 | 少妇精品| 午夜久久电影 | 污污视频在线观看免费 | 日韩日b | 成人精品视频一区二区 | 亚洲午夜福利在线观看 | 欧美成人视屏 | 啦啦啦免费高清视频在线观看 | 麻豆911| 中文字幕被公侵犯的漂亮人妻 | 欧美成人免费一级 | 欧美日韩一区在线观看 | 精品无码人妻一区二区三 | 午夜三级福利 | 日韩中文在线播放 | 爱情岛论坛亚洲入口 | 奇米视频在线 | 嫩草影院懂你的影院 | 一级片免费在线观看 | 亚洲一区二区三区在线免费观看 | 少妇免费毛片久久久久久久久 | 性色av蜜臀av | 女女同性女同一区二区三区按摩 | 丁香婷婷久久 | 91免费版黄 | 一本久草 | 欧美乱妇高清无乱码 | 欧美小视频在线观看 | 少妇愉情理伦片bd | 中文一二三区 | 丁香婷婷久久 | 亚洲一区二区三区综合 | 在线看国产视频 | 无码少妇一级AV片在线观看 | 国产51自产区| 黄色av网站免费在线观看 | 亚洲va欧美 | 久久免费成人 | 久久午夜精品 | 亚洲精品一区二区三区新线路 | 欧美一二级 | 中文字幕在线国产 | 国产精品成人aaaa在线 | 免费一级特黄3大片视频 | 欧美女优一区二区 | 香蕉狠狠爱视频 | 日本伦理一区 | 亚洲国产视频在线 | 欧美69影院 | 91美女片黄在线观看 | 一级特黄aaa大片 | 最新成人 | 久久国产香蕉 | 国产无套在线观看 | 日韩制服诱惑 | a一级网站 | a猛片免费播放 | 欧美综合成人 | 日本一区二区三区四区在线观看 | 精品无码成人久久久久久免费 | 欧美在线观看一区二区三区 | 91精品视频免费观看 | 手机在线不卡av | 精品一区二区在线视频 | 国精产品一区一区三区有限公司杨 | 综合国产精品 | 欧美激情亚洲色图 |