Skip to content

Commit

Permalink
Update ILL
Browse files Browse the repository at this point in the history
  • Loading branch information
klsruan committed Oct 30, 2023
1 parent ba92a61 commit f02128b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
5 changes: 5 additions & 0 deletions DependencyControl.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@
"name": "/Util.moon",
"url": "@{fileBaseUrl}@{fileName}",
"sha1": "df5579ee01f5331bccc32f55c8c15acac6d1f0b9"
},
{
"name": "/UTF8.moon",
"url": "@{fileBaseUrl}@{fileName}",
"sha1": "0260a9d8fc65b1d3ba7fc5c6a643405ab04189d5"
}
],
"requiredModules": [
Expand Down
5 changes: 3 additions & 2 deletions modules/ILL/ILL.moon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module_version = "1.4.2"
module_version = "1.4.3"

haveDepCtrl, DependencyControl = pcall require, "l0.DependencyControl"

Expand Down Expand Up @@ -28,6 +28,7 @@ import Config from require "ILL.ILL.Config"
import Math from require "ILL.ILL.Math"
import Table from require "ILL.ILL.Table"
import Util from require "ILL.ILL.Util"
import UTF8 from require "ILL.ILL.UTF8"
import Ass from require "ILL.ILL.Ass.Ass"
import Curve from require "ILL.ILL.Ass.Shape.Curve"
import Path from require "ILL.ILL.Ass.Shape.Path"
Expand All @@ -40,7 +41,7 @@ import Text from require "ILL.ILL.Ass.Text.Text"
import Font from require "ILL.ILL.Font.Font"

modules = {
:Aegi, :Config, :Math, :Table, :Util
:Aegi, :Config, :Math, :Table, :Util, :UTF8
:Curve, :Path, :Point, :Segment
:Tag, :Tags, :Text
:Ass, :Line
Expand Down
21 changes: 17 additions & 4 deletions modules/ILL/ILL/Ass/Line.moon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Aegi from require "ILL.ILL.Aegi"
import Math from require "ILL.ILL.Math"
import Table from require "ILL.ILL.Table"
import Util from require "ILL.ILL.Util"
import UTF8 from require "ILL.ILL.UTF8"
import Tags from require "ILL.ILL.Ass.Text.Tags"
import Text from require "ILL.ILL.Ass.Text.Text"
import Path from require "ILL.ILL.Ass.Shape.Path"
Expand Down Expand Up @@ -96,13 +97,23 @@ class Line
.shape = .text_stripped
.text_stripped = ""

font = Font .data

-- gets the metric values of the text
if textIsBlank
.width, .height, .descent, .external_leading = aegisub.text_extents .data, " "
textExtents = font\getTextExtents " "
.width = 0
.height = textExtents.height
else
.width, .height, .descent, .external_leading = aegisub.text_extents .data, .isShape and "" or .text_stripped
.width *= video_x_correct_factor
textValue = .isShape and "" or .text_stripped
textExtents = font\getTextExtents textValue
textMetrics = font\getMetrics textValue
.width = textExtents.width * video_x_correct_factor
.height = textExtents.height
.ascent = textMetrics.ascent
.descent = textMetrics.descent
.internal_leading = textMetrics.internal_leading
.external_leading = textMetrics.external_leading

-- text alignment
{:an} = .data
Expand Down Expand Up @@ -475,7 +486,9 @@ class Line
-- sets new values
lineBlock.data.scale_x = 100
lineBlock.data.scale_y = 100
lineBlock.width, lineBlock.height = aegisub.text_extents lineBlock.data, lineBlock.text_stripped
textExtents = Font(lineBlock.data)\getTextExtents lineBlock.text_stripped
lineBlock.width = textExtents.width
lineBlock.height = textExtents.height
-- converts the text to shape and then converts the shape to Path
newShape = Line.toPath lineBlock
-- makes the process of expanding shape
Expand Down
29 changes: 29 additions & 0 deletions modules/ILL/ILL/UTF8.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- code taken from the Yutils lib
-- https://github.com/TypesettingTools/Yutils/blob/91a4ac771b08ecffdcc8c084592286961d99c5f2/src/Yutils.lua#L587

class UTF8

new: (@s) =>

charrange: (s, i) ->
byte = s\byte i
return not byte and 0 or byte < 192 and 1 or byte < 224 and 2 or byte < 240 and 3 or byte < 248 and 4 or byte < 252 and 5 or 6

chars: =>
{:s} = @
charI, sPos, sLen = 0, 1, #s
->
if sPos <= sLen
currPos = sPos
sPos += UTF8.charrange s, sPos
if sPos - 1 <= sLen
charI += 1
return charI, s\sub currPos, sPos - 1

len: (s) ->
n = 0
for ci in @chars!
n += 1
return n

{:UTF8}

0 comments on commit f02128b

Please sign in to comment.