Skip to content

Commit

Permalink
Merge pull request #8 from JuliaComputing/kr/fix1.11
Browse files Browse the repository at this point in the history
fix: include widths.json as a julia file
  • Loading branch information
krynju authored Oct 17, 2024
2 parents 5a15aa1 + 80ad54d commit 8004e21
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
6 changes: 1 addition & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
name = "Badges"
uuid = "f8f3bd14-6f44-485b-add6-c2abd0d3421f"
authors = ["Avik Sengupta"]
version = "1.0.0"

[deps]
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
version = "1.0.1"

[compat]
JSON3 = "1.0"
julia = "1.3"

[extras]
Expand Down
26 changes: 10 additions & 16 deletions src/Badges.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Badges
using JSON3

include("widths.jl")

export Badge
global const gFontFamily = "font-family='Verdana,Geneva,DejaVu Sans,sans-serif'"
const gFontFamily = "font-family='Verdana,Geneva,DejaVu Sans,sans-serif'"

function roundUpToOdd(x)
x = round(Int, x)
Expand Down Expand Up @@ -263,11 +264,6 @@ function escapeXml(s)
x -> replace(x, '\'' => "'")
end

# Verdana font metrics precalculated from the npm package anafanafo
# =================================================================

global const data = Ref{Any}()
global const em = Ref{Float64}()

"""
`widthOfCharCode(charCode; approx=true)`
Expand All @@ -277,13 +273,13 @@ If `approx` is true, any unknwon character will be measured as 'm'. Otherwise 0.
"""
function widthOfCharCode(charCode; approx=true)
if isControlChar(charCode); return 0.0; end
res = findfirst(data[]) do x
charCode >= x[1] && charCode <= x[2]
res = findfirst(WIDTHS) do x
charCode >= x[1][1] && charCode <= x[1][2]
end
if isnothing(res)
if approx; return em[]; else return 0.0; end
if approx; return EM; else return 0.0; end
else
return data[][res][3]
return WIDTHS[res][2]
end
end

Expand All @@ -294,11 +290,9 @@ widthOf(text::AbstractString; approx=true) = reduce(+, [widthOfCharCode(Int(x),

isControlChar(charCode) = charCode <=31 || charCode == 127

# Verdana font metrics precalculated from the npm package anafanafo
# =================================================================

function __init__()
modulepath = dirname(pathof(Badges))
data[] = JSON3.read(read("$modulepath/widths.json", String))
em[] = widthOfCharCode(Int('m'))
end
const EM = widthOfCharCode(Int('m'))::Float64

end
3 changes: 3 additions & 0 deletions src/widths.jl

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/widths.json

This file was deleted.

2 comments on commit 8004e21

@krynju
Copy link
Member Author

@krynju krynju commented on 8004e21 Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117478

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.1 -m "<description of version>" 8004e2169e861ac3308c1b9d3da4f3fd7bb6d29f
git push origin v1.0.1

Please sign in to comment.