Commit 1449475f authored by mrodzis's avatar mrodzis 🌎
Browse files

Use tble-api for height computation

parent 54cd85c8
......@@ -19,6 +19,7 @@ declare namespace test="http://exist-db.org/xquery/xqsuite";
declare namespace xlink="http://www.w3.org/1999/xlink";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace functx="http://www.functx.com";
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";
import module namespace tbleapi="https://fontane-nb.dariah.eu/tble" at "../tble-api.xqm";
import module namespace index-info="http://fontane-nb.dariah.eu/index-info" at "index-info.xqm";
......@@ -964,29 +965,35 @@ as element(tei:term)* {
: @param $current-uri The URI of the current notebook, e.g. '16b00' :)
declare function fontaneSimple:get-height-in-mm($current-uri as xs:string,
$xml-id as xs:string) as xs:string {
let $tble-coll := collection("/db/sade-projects/textgrid/data/xml/tile/")
let $full-uri := "textgrid:" || $current-uri
let $file := for $res in $tble-coll return
(: REGEX is necessary to be independent from revisions :)
if($res//tei:link[matches(@targets, $full-uri || "\.[0-9]+#" || $xml-id)
and matches(@targets, "shape")]) then
$res
else
"Not found"
return
if($file = "Not found") then
""
else
let $bla := util:log-system-out($full-uri)
let $bla := util:log-system-out($file)
let $shape := $file//tei:link[matches(@targets, $full-uri || "\.[0-9]+#" || $xml-id)
and matches(@targets, "shape")]/@targets
=> substring-before(" ")
=> replace("#", "")
let $shape-info := $file//svg:*[@id = $shape]
let $height-percent := xs:double($shape-info/@height => replace("%", ""))
let $width-percent := xs:double($shape-info/@width => replace("%", ""))
let $ratio := $height-percent div $width-percent
(: print area has a width of 113mm :)
return xs:string(113 * $ratio)
let $url := tbleapi:get-url($current-uri, $xml-id, "png")
let $height-percent := xs:double(local:get-height-percent($url))
let $width-percent := xs:double(local:get-width-percent($url))
let $ratio := $height-percent div $width-percent
(: print area has a width of 113mm :)
return xs:string(113 * $ratio)
};
(:https://textgridlab.org/1.0/digilib/rest/IIIF/textgrid:164hd/pct:7.468949311849614,12.023834858480528,40.56730446458543,38.518833794424346/,1000/0/default.png:)
(:let $url := "https://textgridlab.org/1.0/digilib/rest/IIIF/"
|| $image || '/pct:' || $x || ',' || $y || ',' || $w || ',' || $h
|| "/,1000/" || $rotation || "/default." || $format:)
declare function local:get-height-percent($url as xs:string) {
let $parameters := local:get-parameters($url)
return
$parameters[4]
};
declare function local:get-width-percent($url as xs:string) {
let $parameters := local:get-parameters($url)
return
$parameters[3]
};
declare function local:get-parameters($url as xs:string) as xs:string* {
substring-after($url, "pct:")
=> substring-before("/,1000")
=> tokenize(",")
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment