Skip to content

Commit

Permalink
縦書きをObject化
Browse files Browse the repository at this point in the history
  • Loading branch information
new-sankaku committed Oct 12, 2024
1 parent 693269e commit 3615c39
Show file tree
Hide file tree
Showing 51 changed files with 1,556 additions and 4,619 deletions.
1 change: 1 addition & 0 deletions SP-MangaEditer/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 14 additions & 12 deletions SP-MangaEditer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,18 @@
<div id="tool-area" style="display: none;">
<div class="area-header" data-i18n="tools">Tools</div>
<div id="tool-buttons">
<button id="MarkerButton" onclick="switchPencilType('Marker')">
<span data-i18n="Marker">Marker</span>
<img src="03_images/preset/brush/Marker.webp" alt="Marker Icon" style="width: 100%;">
</button>
<button id="InkButton" onclick="switchPencilType('Ink')">
<span data-i18n="ink">Ink</span>
<img src="03_images/preset/brush/Ink.webp" alt="Ink Icon" style="width: 100%;">
</button>
<button id="CrayonButton" onclick="switchPencilType('Crayon')">
<span data-i18n="crayon">Crayon</span>
<img src="03_images/preset/brush/Crayon.webp" alt="Crayon Icon" style="width: 100%;">
</button>
<button id="PencilButton" onclick="switchPencilType('Pencil')">
<span data-i18n="Pencil">Pencil</span>
<img src="03_images/preset/brush/Pencil.webp" alt="Pencil Icon" style="width: 100%;">
Expand All @@ -1015,18 +1027,6 @@
<span data-i18n="Circle">Circle</span>
<img src="03_images/preset/brush/Circle.webp" alt="Circle Icon" style="width: 100%;">
</button>
<button id="CrayonButton" onclick="switchPencilType('Crayon')">
<span data-i18n="crayon">Crayon</span>
<img src="03_images/preset/brush/Crayon.webp" alt="Crayon Icon" style="width: 100%;">
</button>
<button id="InkButton" onclick="switchPencilType('Ink')">
<span data-i18n="ink">Ink</span>
<img src="03_images/preset/brush/Ink.webp" alt="Ink Icon" style="width: 100%;">
</button>
<button id="MarkerButton" onclick="switchPencilType('Marker')">
<span data-i18n="Marker">Marker</span>
<img src="03_images/preset/brush/Marker.webp" alt="Marker Icon" style="width: 100%;">
</button>

<button id="MosaicButton" onclick="switchPencilType('Mosaic')">
<span data-i18n="Mosaic">Mosaic</span>
Expand Down Expand Up @@ -1808,6 +1808,8 @@
<script src="js/sidebar/Sidebar.js?v=5.3" defer></script>
<script src="js/sidebar/text/TextEffect.js?v=5.3" defer></script>
<script src="js/sidebar/text/VerticalText.js?v=5.3" defer></script>
<script src="js/sidebar/text/VerticalTextbox.js?v=5.3"></script>

<script src="js/sidebar/speechBubble/SpeechBubbleEffect.js?v=5.3" defer></script>
<script src="js/sidebar/speechBubble/SpeechBubbleFreeHand.js?v=5.3" defer></script>
<script src="js/sidebar/pen/OriginalBrush.js?v=5.3" defer></script>
Expand Down
21 changes: 0 additions & 21 deletions SP-MangaEditer/js/event/FabricManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,6 @@ canvas.on('selection:updated', function(event) {
}
});

//縦書きTextのフローティングウインドウ表示処理
canvas.on("selection:created", function () {
const selectedObject = canvas.getActiveObject();
if (isVerticalText(selectedObject)) {
openModalForEditing();
} else {
myWindow.style.display = "none";
}
});
canvas.on("selection:updated", function () {
const selectedObject = canvas.getActiveObject();
if (isVerticalText(selectedObject)) {
openModalForEditing();
} else {
myWindow.style.display = "none";
}
});
canvas.on("selection:cleared", closeWindow);



function moveSettings(img, poly) {
updateClipPath(img, poly);

Expand Down
1 change: 1 addition & 0 deletions SP-MangaEditer/js/layer/ImageHistoryManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function lastRedo(guid = null) {
currentStateIndex = stateStack.length - 1;

let state = restoreImage(stateStack[stateStack.length - 1]);
// console.log("state", JSON.stringify(state));
canvas.loadFromJSON(state, function () {
if( guid ){
setCanvasGUID( guid );
Expand Down
14 changes: 9 additions & 5 deletions SP-MangaEditer/js/layer/LayerManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ function updateLayerPanel() {
var fullText = layer.text;
nameTextArea.value = fullText.substring(0, 20);
} else if (isVerticalText(layer)) {
var fullText = layer
.getObjects()
.map((obj) => obj.text)
.join("");
nameTextArea.value = fullText.substring(0, 15);
var fullText = layer.name;
if( fullText ){
nameTextArea.value = fullText.substring(0, 15);
}else{
layer.name = "verticalText";
fullText = layer.name;
nameTextArea.value = fullText.substring(0, 15);
}

}

setNameTextAreaProperties(layer, nameTextArea, index);
Expand Down
48 changes: 28 additions & 20 deletions SP-MangaEditer/js/sidebar/text/TextEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ function rgbToHex(rgb) {

function updateTextControls(object) {
if (isVerticalText(object)) {
let firstText = object.getObjects('text')[0];
let inheritedColor = firstText ? firstText.fill : $("textColorPicker").value;
$('textColorPicker').value = inheritedColor;
if (object.fill) {
return;
} else {
let hexColor = rgbToHex(object.fill);
$('textColorPicker').value = hexColor;
}
} else if (isText(object)) {
if (object.fill) {
return;
Expand Down Expand Up @@ -174,12 +177,29 @@ function applyNeonEffect() {

var textAlignment = 'left';
function alignText(alignment) {

console.log("call alignment");
textAlignment = alignment;
var activeObject = canvas.getActiveObject();
if (activeObject && isText(activeObject)) {

if( isVerticalText(activeObject) ){
switch(alignment){
case "left":
textAlignment = "top";
break
case "center":
textAlignment = "middle";
break
case "right":
textAlignment = "bottom";
break
}
activeObject.set('verticalAlign', textAlignment);
activeObject.set('dirty', true);
}else if(isText(activeObject)){
activeObject.set('textAlign', alignment);
canvas.renderAll();
}
canvas.renderAll();
updateTextSelectedButton(alignment);
}

Expand Down Expand Up @@ -258,11 +278,7 @@ function changeFontSize(size) {
function changeStrokeWidthSize(size) {
var activeObject = canvas.getActiveObject();
if (isVerticalText(activeObject)) {
activeObject.getObjects().forEach(function (obj) {
if (obj.type === 'text') {
obj.set("strokeWidth", parseInt(size));
}
});
activeObject.set("strokeWidth", parseInt(size));
canvas.renderAll();
} else if (isText(activeObject)) {
activeObject.set("strokeWidth", parseInt(size));
Expand All @@ -275,11 +291,7 @@ function changeTextColor(color) {
var activeObject = canvas.getActiveObject();

if (isVerticalText(activeObject)) {
activeObject.getObjects().forEach(function (obj) {
if (obj.type === 'text') {
obj.set("fill", color);
}
});
activeObject.set("fill", color);
canvas.renderAll();
} else if (isText(activeObject)) {
activeObject.set("fill", color);
Expand All @@ -290,11 +302,7 @@ function changeOutlineTextColor(color) {
var activeObject = canvas.getActiveObject();

if (isVerticalText(activeObject)) {
activeObject.getObjects().forEach(function (obj) {
if (obj.type === 'text') {
obj.set("stroke", color);
}
});
activeObject.set("stroke", color);
canvas.renderAll();
} else if (isText(activeObject)) {
activeObject.set("stroke", color);
Expand Down
194 changes: 13 additions & 181 deletions SP-MangaEditer/js/sidebar/text/VerticalText.js
Original file line number Diff line number Diff line change
@@ -1,188 +1,20 @@
var openButton = null;
var myWindow = null;
var textInput = null;

let isDragging = false;
let offsetX, offsetY;

document.addEventListener('DOMContentLoaded', function() {

openButton = $("openWindow");
myWindow = $("myWindow");
textInput = $("vertical_textInput");

openButton.addEventListener("click", function () {
const activeObject = canvas.getActiveObject();
if (isVerticalText(activeObject)) {
textInput.value = activeObject._objects.map((obj) => obj.text).join("");
} else {
textInput.value = "";
}
myWindow.style.display = "block";
let style = {
"fill": "#292929",
"editable": true,
"fontSize": 30,
"left": 100,
"top": 50,
"width": 100,
"height": 100
};

const cjkText = new VerticalTextbox("new", style);
canvas.add(cjkText);
});
});


function closeWindow() {
myWindow.style.display = "none";
}

document.addEventListener('DOMContentLoaded', function() {
const header = myWindow.querySelector(".header");
header.addEventListener("mousedown", function (e) {
offsetX = e.clientX - myWindow.offsetLeft;
offsetY = e.clientY - myWindow.offsetTop;
isDragging = true;
});

document.addEventListener("mousemove", function (e) {
if (isDragging) {
myWindow.style.left = `${e.clientX - offsetX}px`;
myWindow.style.top = `${e.clientY - offsetY}px`;
}
});

document.addEventListener("mouseup", function () {
isDragging = false;
});


fabric.VerticalText = fabric.util.createClass(fabric.Group, {
type: 'verticalText',

initialize: function(elements, options) {
this.callSuper('initialize', elements, options);
},

toObject: function() {
return fabric.util.object.extend(this.callSuper('toObject'), {
type: 'verticalText'
});
},

setGradientFill: function(gradient) {
this.getObjects().forEach(function(obj) {
obj.set('fill', gradient);
});
}
});


fabric.VerticalText.fromObject = function(object, callback) {
fabric.util.enlivenObjects(object.objects, function(enlivenedObjects) {
delete object.objects;
callback(new fabric.VerticalText(enlivenedObjects, object));
});
};

fabric.Object.prototype.verticalText = fabric.VerticalText;


});


let textGroup;
function createVerticalText(textString, options) {
var selectedFont = $('fontSelector').value;
const ignoreRegex = /[・・・…ー(){}「」(){}『』【】[\]]/;
const reverceRegex = /[、。,A-Za-z0-9!"#$%&'()=~{`+*}_?><]/;

const chars = textString.split("");
const groupItems = [];
let offsetX = options.left || 0;
let offsetY = options.top || 0;
const lineHeight = options.fontSize * 1.2;

changeDoNotSaveHistory();
chars.forEach((char, index) => {
const isIgnored = ignoreRegex.test(char);
const isReverce = reverceRegex.test(char);
const text = new fabric.Text(char, {
left: offsetX,
top: offsetY,
fontSize: options.fontSize,
originX: isIgnored ? "right" : "left",
originY: "bottom",
fill: options.color,
fontFamily: selectedFont,
angle: isIgnored ? 90 : 0,
stroke: $("textOutlineColorPicker").value,
strokeWidth: 1,
});

canvas.add(text);
const textWidth = text.width * text.scaleX;
const actualHeight = text.height * text.scaleY;
text.set({ top: offsetY + actualHeight });
text.set({ left: isReverce ? offsetX + textWidth / 2 : offsetX });
groupItems.push(text);
canvas.remove(text);

if (char === "\n") {
offsetX -= lineHeight;
offsetY = options.top || 0;
} else {
offsetY += actualHeight;
}
});
changeDoSaveHistory();

const group = new fabric.VerticalText(groupItems, {
selectable: true,
type: 'verticalText'
});

group.setControlsVisibility({
mt: false,
mb: false,
ml: false,
mr: false,
});

return group;
}

function updateVerticalText() {
const textString = $("vertical_textInput").value;
const selectedObject = canvas.getActiveObject();

if ( isVerticalText(selectedObject) ) {
canvas.remove(selectedObject);

let firstText = selectedObject.getObjects('text')[0];
let inheritedFontSize = firstText ? firstText.fontSize : parseInt($('fontSizeSlider').value);
let inheritedColor = firstText ? firstText.fill : $("textColorPicker").value;

const newTextGroup = createVerticalText(textString, {
left: selectedObject.left,
top: selectedObject.top,
fontSize: inheritedFontSize,
color: inheritedColor
});
canvas.add(newTextGroup);
} else {
const newTextGroup = createVerticalText(textString, {
top: 50,
left: 300,
fontSize: parseInt($('fontSizeSlider').value),
color: $("textColorPicker").value
});
canvas.add(newTextGroup);
}

closeWindow();
}

$("cancelButton").addEventListener("click", closeWindow);
$("updateButton").addEventListener("click", updateVerticalText);

function openModalForEditing() {
const selectedObject = canvas.getActiveObject();
if (isVerticalText(selectedObject)) {
textInput.value = selectedObject._objects.map((obj) => obj.text).join("");
myWindow.style.display = "block";
} else {
textInput.value = "";
myWindow.style.display = "block";
}
}
fabric.VerticalTextbox = VerticalTextbox;
1 change: 1 addition & 0 deletions SP-MangaEditer/js/sidebar/text/VerticalTextbox.js

Large diffs are not rendered by default.

Loading

0 comments on commit 3615c39

Please sign in to comment.