From 7aea53ad4365d1c94fa821f17a3db44d697d3312 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Mon, 19 Apr 2021 14:23:16 +0900 Subject: [PATCH] Borrow some code from fonts-rpm-macros, to drop a dependant code to generate srpm --- google-noto-fonts.spec | 102 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/google-noto-fonts.spec b/google-noto-fonts.spec index d78d39b..e44467e 100644 --- a/google-noto-fonts.spec +++ b/google-noto-fonts.spec @@ -514,8 +514,106 @@ local function genfcconf(table) _fcconfbuild = (_fcconfbuild ~= '' and _fcconfbuild .. "\n" or '') .. "cat<<_EOL_>" .. table.fcconf .. "\\\n" .. xml .. "\n_EOL_\\" end +-- Borrowed from fonts-rpm-macros +-- koji doesn't sasisfy BR during generating srpm yet. +-- We can't add a dependant code to fonts-rpm-macros at this stage. + +-- https://github.com/rpm-software-management/rpm/issues/566 +-- Reformat a text intended to be used used in a package description, removing +-- rpm macro generation artefacts. +-- – remove leading and ending empty lines +-- – trim intermediary empty lines to a single line +-- – fold on spaces +-- Should really be a %%{wordwrap:…} verb +local function wordwrap(text) + text = rpm.expand(text .. "\n") + text = string.gsub(text, "\t", " ") + text = string.gsub(text, "\r", "\n") + text = string.gsub(text, " +\n", "\n") + text = string.gsub(text, "\n+\n", "\n\n") + text = string.gsub(text, "^\n", "") + text = string.gsub(text, "\n( *)[-*—][  ]+", "\n%1– ") + output = "" + for line in string.gmatch(text, "[^\n]*\n") do + local pos = 0 + local advance = "" + for word in string.gmatch(line, "%s*[^%s]*\n?") do + local wl, bad = utf8.len(word) + if not wl then + print("%{warn:Invalid UTF-8 sequence detected in:}" .. + "%{warn:" .. word .. "}" .. + "%{warn:It may produce unexpected results.}") + wl = bad + end + if (pos == 0) then + advance, n = string.gsub(word, "^(%s*– ).*", "%1") + if (n == 0) then + advance = string.gsub(word, "^(%s*).*", "%1") + end + advance = string.gsub(advance, "– ", " ") + pos = pos + wl + elseif (pos + wl < 81) or + ((pos + wl == 81) and string.match(word, "\n$")) then + pos = pos + wl + else + word = advance .. string.gsub(word, "^%s*", "") + output = output .. "\n" + pos = utf8.len(word) + end + output = output .. word + if pos > 80 then + pos = 0 + if not string.match(word, "\n$") then + output = output .. "\n" + end + end + end + end + output = string.gsub(output, "\n*$", "\n") + return output +end + +-- Reformat some text into something that can be included in an AppStream +-- XML description +local function txt2xml(text) + local text = wordwrap(text) + local output = "" + local oldtag = nil + local oldadvance = nil + local newtag = nil + text = string.gsub(text, "^\n*", "") + text = string.gsub(text, "\n*$", "\n") + for line in string.gmatch(text, "[^\n]*\n") do + local change = true + local advance, n = string.gsub(line, "^(%s*– ).*", "%1") + if (n == 1) then + newtag = "li" + else + advance = string.gsub(line, "^(%s*).*", "%1") + if (line == "\n") then + newtag = nil + elseif (advance ~= oldadvance) then + newtag = "p" + else + change = false + end + end + local result = "" + if change then + result = string.gsub(line, "^" .. advance, switchtag(oldtag,newtag)) + oldtag = newtag + oldadvance = string.gsub(advance, "– ", " ") + else + result = string.gsub(line, "^" .. advance, " ") + end + result = string.gsub(result, "\n$", "") + output = output .. result + end + output = output .. closetag(oldtag, nil) + return output +end + local function genmetainfo(table) - local fonts = require "fedora.rpm.fonts" local xmlfontname = '$(cmd=$(for f in %{buildroot}' .. table.filename .. '; do fc-scan "$f" -f "echo \\\\\" %{fullname[0]}\\\\\";"; done); if test x"$cmd" != x; then echo "echo \\\\\" \\\\\"; $cmd echo \\\\\" \\\\\""|sh; fi|grep -v "font>%{lang}\\\\\";}}"; done); if test x"$cmd" != x; then echo "echo \\\\\" \\\\\"; ($cmd)|sort -u; echo \\\\\" \\\\\""|sh; fi)' local xml = [[ @@ -528,7 +626,7 @@ local function genmetainfo(table) Noto ]] .. table.family .. [[\ \ \ -]] .. fonts.txt2xml(table.description) .. "\\\n" .. [[ +]] .. txt2xml(table.description) .. "\\\n" .. [[ \ ]] .. rpm.expand("%{fontcontact}") .. [[\ ]] .. rpm.expand("%{url}") .. [[\