Write string on canvas.
How do I make an write string on canvas.?
What is a write string on canvas.? How do you make a write string on canvas.? This script and codes were developed by Kazuki Harada on 09 December 2022, Friday.
Write string on canvas. - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>write string on canvas.</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html ng-app="app"> <head> <link rel="stylesheet prefetch" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> </script> </head> <body> <div class="container" ng-controller="sampleController"> <h2>帳票定義リストを作成する</h2> <form class="form-horizontal" name="sampleForm" novalidate> <div class="row form-group"> <div class="col-xs-3"> <input type="text" placeholder="property" class="form-control" ng-model="propName"> </div> <div class="col-xs-6"> <input type="text" placeholder="value" class="form-control" ng-model="propValue"> </div> <div class="col-xs-3"> <input type="button" class="form-control btn btn-primary" value="設定" ng-click="set()"> </div> </div> <div class="row form-group"> <div class="col-xs-9"><p><pre>{{lineModel | json}}</pre></p></div> <div class="col-xs-3"> <input type="button" class="form-control btn btn-primary" value="追加" ng-click="add()"> </div> </div> </form> <p><pre>{{confList | json}}</pre></p> <h2>出力パラメータモデルを作成する</h2> <form class="form-horizontal" name="sampleForm" novalidate> <div class="row form-group"> <div class="col-xs-3"> <input type="text" placeholder="parameter" class="form-control" ng-model="paramName"> </div> <div class="col-xs-6"> <input type="text" placeholder="value" class="form-control" ng-model="paramValue"> </div> <div class="col-xs-3"> <input type="button" class="form-control btn btn-primary" value="設定" ng-click="setParameter()"> </div> </div> </form> <p><pre>{{parameterModel | json}}</pre></p> <pre> 作成日 {{parameterModel.createDay | date: 'yyyy年M月d日 H時m分s秒'}} 更新日 {{parameterModel.updateDay | date: 'yyyy/MM/dd HH:mm:ss'}} 本日の結果 住所 {{parameterModel.address}} 名前 {{parameterModel.userName}} </pre> <h2>文字をキャンバスに描く</h2> <canvas width="1180" height="500" id="canvas" class="draw-block" draw-report></canvas>
<form class="form-horizontal" name="sampleForm" novalidate> <div class="row form-group"> <div class="col-xs-3"> <input type="number" placeholder="font size" class="form-control" ng-model="fontSize"> </div> <div class="col-xs-3"> <input type="number" placeholder="line spacing" class="form-control" ng-model="lineSpacing"> </div> <div class="col-xs-3"> <select class="form-control" ng-model="textAlign" ng-init="alignList=[{name: '左寄せ', value: 'left'}, {name: '中央', value: 'center'}, {name: '右寄せ', value: 'right'} ]" ng-options="align.value as align.name for align in alignList"> </select> </div> <div class="col-xs-3"> </div> </div> <div class="row form-group"> <div class="col-xs-9"> <input type="text" placeholder="value" class="form-control" ng-model="textValue"> </div> <div class="col-xs-3"> <input type="button" class="form-control btn btn-primary" value="書き出し" ng-click="writeTextForCanvas(textValue, fontSize, lineSpacing, textAlign)"> </div> </div> </form> </div> </body>
</html> <script src="js/index.js"></script>
</body>
</html>
Write string on canvas. - Script Codes CSS Codes
.draw-block{ border-bottom: 1px solid rgba(0,0,0,0.3); background-color: #FFF; box-shadow: 0 9px 20px -5px rgba(0,0,0,0.8); margin-left : auto ; margin-right : auto ; display: block;
}
Write string on canvas. - Script Codes JS Codes
var app = angular.module('app', []);
app.controller('sampleController', function ($scope, $log, $compile) { $scope.confList = []; $scope.set = function(){ if(!$scope.lineModel){ $scope.lineModel = new Object(); } $scope.lineModel[$scope.propName] = $scope.propValue; }; $scope.add = function(){ if($scope.lineModel){ $scope.confList.push($scope.lineModel); delete $scope.lineModel; } }; $scope.setParameter = function(){ if(!$scope.parameterModel){ $scope.parameterModel = new Object(); $scope.parameterModel.today = new Date(); } $scope.parameterModel[$scope.paramName] = $scope.paramValue; };
});
app.directive("drawReport", function(){ return { restrict: "A", link: function(scope, element, attrs){ var canvas = element[0]; var width = canvas.width; var ctx = canvas.getContext('2d'); ctx.lineCap = "round"; ctx.lineJoin = "round"; ctx.strokeStyle = "#000"; ctx.fillStyle = "#000"; ctx.lineWidth = 6; ctx.textBaseline = 'top'; ctx.font = "30px 'MS ゴシック'"; var currentPos = 10; scope.writeTextForCanvas = function(text, fontsz, linesz, textAlign){ console.log("write... " + text); ctx.save(); ctx.font = fontsz + "px 'MS ゴシック'"; ctx.textAlign = textAlign; if(textAlign == 'left'){ ctx.fillText(text, 10, currentPos); }else if(textAlign == 'center'){ ctx.fillText(text, Math.round(width / 2), currentPos); }else if(textAlign == 'right'){ ctx.fillText(text, width-10, currentPos); } currentPos = currentPos + fontsz + linesz; ctx.restore(); }; } };
});
Developer | Kazuki Harada |
Username | kazux |
Uploaded | December 09, 2022 |
Rating | 3 |
Size | 3,317 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Kazuki Harada | 1,705 Kb |
Write char on canvas. | 3,802 Kb |
Infinite-scroll list | 1,795 Kb |
AngularJS Validate Test | 2,630 Kb |
Flip switch on angular | 3,110 Kb |
Format text at blur | 3,857 Kb |
Canvas with AngularJS | 3,035 Kb |
Datepicker | 2,319 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Background Images | Jooonebug | 2,100 Kb |
Bezier Animation with straight paths | Rhernando | 2,087 Kb |
Animated rainbow wave on canvas | Icodeforlove | 2,777 Kb |
Bootstrap 3 Price Table | Honglio | 2,655 Kb |
APortfolio | Skybutterfly | 5,174 Kb |
Light Switch | Bartuc | 4,933 Kb |
Airbnb Homepage | SindhujaD | 2,480 Kb |
Three js | Paulq | 2,353 Kb |
Cars going | Netoguimaraes | 1,699 Kb |
BenU Maintenance Site | Ksherman | 4,893 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!