Commit 081fff4b authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

refactor digilib function to allow tile crops on tei:graphic

parent 2e833fdd
......@@ -1468,147 +1468,178 @@ declare function transfo:facs($node) {
attribute class {('facs', string( ($node/@subtype)[1] ))},
attribute src {transfo:digilib($node)}
},
if($node/tei:graphic[2])
then
for $graphic in $node/tei:graphic[position() gt 1]
let $tgUri := $graphic/substring-after(@url, "textgridrep.org/")
let $src :=
if($graphic/@xml:id)
then
transfo:image-tile($graphic) => replace("/,500/", "/,1500/")
else
transfo:image($graphic) => replace("textgrid:.[a-z0-9]{4,5}", $tgUri)
return
element xhtml:div {
attribute class {'alt-facs'},
element xhtml:a {
attribute data-src {transfo:digilib($node) => replace("textgrid:.[a-z0-9]{4,5}", $tgUri)},
attribute data-src { $src },
attribute data-href {"digilib/" || string($graphic/@n) || ".jpg?m2"},
attribute href {"#"},
text { "Alternativer Scan verfügbar" }
}
}
else ())
)
}
}
};
(: test :)
(:~
: prepares URLs to textgrid digilib for given tei:surface
: TODO: should work with tei:graphic
:
: :)
declare function transfo:digilib($node){
(: TILE object available :)
if($node/tei:graphic/@xml:id)
if($node/tei:graphic[1]/@xml:id)
then
transfo:image-tile($node/tei:graphic[1])
else
(: typical cover :)
transfo:image($node/tei:graphic[1])
};
let $id := ($node/tei:graphic/string(@xml:id))[1]
let $uri := $node/ancestor::tei:TEI//tei:publicationStmt//tei:idno[@type="TextGrid"]/string(.)
(:~
:
: prepares a URL to digilib (IIIF) for a given tei element
:
: @param $graphic a tei element like graphic or figure with a xml:id
: @return a URL to digilib
: :)
declare function transfo:image-tile($graphic as element(*))
as xs:string {
let $id := $graphic/string(@xml:id)
let $uri := $graphic/root()//tei:publicationStmt//tei:idno[@type="TextGrid"]/string(.)
let $link := transfo:newestTBLELink($uri, $id)
let $facs := $link/parent::tei:linkGrp/substring-after(@facs, '#')
let $tei := $link/ancestor::tei:TEI
let $shape := $link/parent::tei:linkGrp/tei:link[contains(@targets, 'shape')][ends-with(@targets, $id)]/substring-before(substring-after(@targets, '#'), ' ')
let $link := transfo:newestTBLELink($uri, $id)
let $facs := $link/parent::tei:linkGrp/substring-after(@facs, '#')
let $tei := $link/ancestor::tei:TEI
let $shape := $link/parent::tei:linkGrp/tei:link[contains(@targets, 'shape')][ends-with(@targets, $id)]/substring-before(substring-after(@targets, '#'), ' ')
let $svgg := $tei//svg:g[@id = $facs]
let $image := string($svgg/svg:image/@xlink:href)
let $image := if ($image = "") then $node/tei:graphic/substring-after(@url, "http://textgridrep.org/") else $image
let $svgg := $tei//svg:g[@id = $facs]
let $image := string($svgg/svg:image/@xlink:href)
let $image := if ($image = "") then $graphic/substring-after(@url, "http://textgridrep.org/") else $image
let $x := number($svgg//svg:rect[@id = $shape]/substring-before(@x, '%')) (: div 100 :)
let $y := number($svgg//svg:rect[@id = $shape]/substring-before(@y, '%')) (: div 100 :)
let $w := number($svgg//svg:rect[@id = $shape]/substring-before(@width, '%')) (: div 100 :)
let $h := number($svgg//svg:rect[@id = $shape]/substring-before(@height, '%')) (: div 100 :)
let $x := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@x, '%')) (: div 100 :)
let $y := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@y, '%')) (: div 100 :)
let $w := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@width, '%')) (: div 100 :)
let $h := xs:decimal($svgg//svg:rect[@id = $shape]/substring-before(@height, '%')) (: div 100 :)
return
'https://textgridlab.org/1.0/digilib/rest/IIIF/'
|| $image
|| '/pct:'
|| string-join(($x, $y, $w, $h), ",")
|| '/,500/0/default.jpg'
return
'https://textgridlab.org/1.0/digilib/rest/IIIF/'
|| $image
|| '/pct:'
|| string-join(($x, $y, $w, $h), ",")
|| '/,500/0/default.jpg'
};
else
(: typical cover :)
(:~
: prepares a URL to digilib
:
: @param $graphic A tei element like graphic and figure
: @return a URL like https://textgridlab.org/1.0/digilib/rest/IIIF/textgrid:164g9.1/pct:7.747474581830108,5.289308105687416,84.44747294194818,89.91823779668606/,1000/0/default.jpg
: :)
declare function transfo:image($graphic as element(*))
as xs:string{
let
$currentNotebook := substring-before( string(($node/tei:graphic/@n)[1]), '_'),
$n := $node/@n,
$type := local-name($node[1]),
$facs := if (not(contains($node/tei:graphic/@n, ' '))) then ($node/tei:graphic/@n)[1] || '.jpg' else substring-before( ($node/tei:graphic/@n)[1] , ' ') || '.jpg',
$facs := $node/tei:graphic[1]/substring-after(@url, "http://textgridrep.org/"), (: complete base uri :)
$surfaceWidth := $node/ancestor::tei:TEI//extent[1]/dimensions[@type = 'leaf']/width[1]/@quantity,
$surfaceHeight := $node/ancestor::tei:TEI//extent[1]/dimensions[@type = 'leaf']/height[1]/@quantity,
$bindingWidth := $node/ancestor::tei:TEI//extent[1]/dimensions[@type = 'binding']/width[1]/number(@quantity),
$bindingHeight := $node/ancestor::tei:TEI//extent[1]/dimensions[@type = 'binding']/height[1]/@quantity,
$dpcm := 236.2205, (: 600 dpi = 236.2205 dpcm :)
$exif := doc('/db/sade-projects/textgrid/data/xml/data/217qs.xml'),
$covertble := doc('/db/sade-projects/textgrid/data/xml/tile/218r2.xml'),
$image-width := number($exif//digilib:image[@uri = $facs]/@width),
$image-height := number($exif//digilib:image[@uri = $facs]/@height),
$plusX := $exif//digilib:offset[@notebook = $currentNotebook][@x]/@x,
$plusX := if ($plusX = '') then 1 else $plusX,
$plusY := $exif//digilib:offset[@notebook = $currentNotebook][@y]/@y,
$plusY := if ($plusY = '') then 1 else $plusY,
$shape := if($type = 'cover' and $exif//digilib:image[@name = $facs]/@xml:id) then (substring-after(substring-before($covertble//tei:link[ends-with(@targets, $exif//digilib:image[@name = $facs]/@xml:id)][1]/@targets, ' '), '#')) else 0,
$scaler := 'https://textgridlab.org/1.0/digilib/rest/digilib?fn=',
$scaler := 'https://textgridlab.org/1.0/digilib/rest/IIIF',
$ulx := $node/@ulx,
$uly := $node/@uly,
$lrx := $node/@lrx,
$lry := $node/@lry,
(: lets start building our url :)
$image := $facs,
$resolution := switch ($type)
case 'thumb' return ("", 150)
case 'thumb-link' return ("", 1500)
case 'surface-empty' return ("", 300)
case 'figure' return ("", 500)
default return ("",1000),
$currentNotebook := substring-before( string($graphic/@n), '_'),
$parent := $graphic/parent::tei:surface,
$n := $parent/@n,
$type := local-name($graphic[1]),
$facs := $graphic/@n || '.jpg',
$facs := $graphic/substring-after(@url, "http://textgridrep.org/"), (: complete base uri :)
$surfaceWidth := $graphic/root()//tei:extent[1]/tei:dimensions[@type = 'leaf']/tei:width[1]/@quantity,
$surfaceHeight := $graphic/root()//tei:extent[1]/tei:dimensions[@type = 'leaf']/tei:height[1]/@quantity,
$bindingWidth := $graphic/root()//tei:extent[1]/tei:dimensions[@type = 'binding']/tei:width[1]/@quantity,
$bindingHeight := $graphic/root()//tei:extent[1]/tei:dimensions[@type = 'binding']/tei:height[1]/@quantity,
$dpcm := 236.2205, (: 600 dpi = 236.2205 dpcm :)
$exif := doc('/db/sade-projects/textgrid/data/xml/data/217qs.xml'),
$covertble := doc('/db/sade-projects/textgrid/data/xml/tile/218r2.xml'),
$image-width := xs:decimal($exif//digilib:image[@uri = $facs]/@width),
$image-height := xs:decimal($exif//digilib:image[@uri = $facs]/@height),
$plusX := $exif//digilib:offset[@notebook = $currentNotebook][@x]/@x,
$plusX := if ($plusX = '') then 1 else $plusX,
$plusY := $exif//digilib:offset[@notebook = $currentNotebook][@y]/@y,
$plusY := if ($plusY = '') then 1 else $plusY,
$shape := if($type = 'cover' and $exif//digilib:image[@name = $facs]/@xml:id) then (substring-after(substring-before($covertble//tei:link[ends-with(@targets, $exif//digilib:image[@name = $facs]/@xml:id)][1]/@targets, ' '), '#')) else 0,
$scaler := 'https://textgridlab.org/1.0/digilib/rest/IIIF',
$ulx := $parent/@ulx,
$uly := $parent/@uly,
$lrx := $parent/@lrx,
$lry := $parent/@lry,
(: lets start building the url :)
$image := $facs,
$resolution :=
switch ($type)
case 'thumb' return ("", 150)
case 'thumb-link' return ("", 1500)
case 'surface-empty' return ("", 300)
case 'figure' return ("", 500)
default return ("",1000),
(: wx , wy :)
$offset := switch($type)
case 'figure' return
if (matches($n, '\d[a-z]*r|Ir$')) then (
(($plusX + $ulx + $surfaceWidth div 10) * $dpcm div $image-width) * 100,
(($plusY + $uly) * $dpcm div $image-height) * 100 )
else if(matches($n, '\d[a-z]*v|Iv$')) then (
(($plusX + $ulx) * $dpcm div $image-width) * 100,
(($plusY + $uly) * $dpcm div $image-height) * 100 )
else ()
case 'cover' return (
number(substring-before($covertble//svg:rect[@id = $shape][1]/@x, '%')),
number(substring-before($covertble//svg:rect[@id = $shape][1]/@y, '%')))
default return
if(contains($n, 'outer')) then (
$dpcm div $image-width * 100,
$dpcm div $image-height * 100 )
else if($n = 'inner_back_cover') then (
number($plusX * $dpcm div $image-width + ($surfaceWidth div 10) * ($dpcm div $image-width)) * 100,
number($plusY * $dpcm div $image-height) * 100)
else if($n = 'inner_front_cover') then (
($dpcm div $image-width) * 100,
($dpcm div $image-height) * 100 )
else if (matches($n, '\d[a-z]*r|Ir$') and not(matches($n, "\dv[a-z]r"))) then (
number($plusX * ($dpcm div $image-width) + ($surfaceWidth div 10) * ($dpcm div $image-width)) * 100,
($plusY * $dpcm div $image-height) * 100)
else if(matches($n, '\d[a-z]*v|Iv$') or matches($n, "\dv[a-z]r")) then (
($plusX * $dpcm div $image-width) * 100,
($plusY * $dpcm div $image-height) * 100 )
else (0, 0),
$offset :=
switch($type)
case 'figure'
return
if (matches($n, '\d[a-z]*r|Ir$')) then (
(($plusX + $ulx + $surfaceWidth div 10) * $dpcm div $image-width) * 100,
(($plusY + $uly) * $dpcm div $image-height) * 100 )
else if(matches($n, '\d[a-z]*v|Iv$')) then (
(($plusX + $ulx) * $dpcm div $image-width) * 100,
(($plusY + $uly) * $dpcm div $image-height) * 100 )
else ()
case 'cover'
return (
xs:decimal(substring-before($covertble//svg:rect[@id = $shape][1]/@x, '%')),
xs:decimal(substring-before($covertble//svg:rect[@id = $shape][1]/@y, '%')))
default
return
if(contains($n, 'outer')) then (
$dpcm div $image-width * 100,
$dpcm div $image-height * 100 )
else if($n = 'inner_back_cover') then (
xs:decimal($plusX * $dpcm div $image-width + ($surfaceWidth div 10) * ($dpcm div $image-width)) * 100,
xs:decimal($plusY * $dpcm div $image-height) * 100)
else if($n = 'inner_front_cover') then (
($dpcm div $image-width) * 100,
($dpcm div $image-height) * 100 )
else if (matches($n, '\d[a-z]*r|Ir$') and not(matches($n, "\dv[a-z]r"))) then (
xs:decimal($plusX * ($dpcm div $image-width) + ($surfaceWidth div 10) * ($dpcm div $image-width)) * 100,
($plusY * $dpcm div $image-height) * 100)
else if(matches($n, '\d[a-z]*v|Iv$') or matches($n, "\dv[a-z]r")) then (
($plusX * $dpcm div $image-width) * 100,
($plusY * $dpcm div $image-height) * 100 )
else (0, 0),
(: ww , wh :)
$range := if ($n = 'none') then (1, 1)
else if ($type = 'figure') then ( (($lrx - $ulx) * $dpcm div $image-width) * 100, (($lry - $uly) * $dpcm div $image-height ) * 100 )
$range :=
if ($type = 'figure') then ( (($lrx - $ulx) * $dpcm div $image-width) * 100, (($lry - $uly) * $dpcm div $image-height ) * 100 )
else if ($type = 'cover' and $exif//digilib:coveroffset[@notebook = $currentNotebook]) then (
number(substring-before($covertble//svg:rect[@id = $shape][1]/@width, '%')) ,
number(substring-before($covertble//svg:rect[@id = $shape][1]/@height, '%')) )
xs:decimal(substring-before($covertble//svg:rect[@id = $shape][1]/@width, '%')) ,
xs:decimal(substring-before($covertble//svg:rect[@id = $shape][1]/@height, '%')) )
else if (contains($n, 'outer')) then (
number(($bindingWidth div 10) * $dpcm div $image-width) * 100,
number(($bindingHeight div 10) * $dpcm div $image-height) * 100 )
xs:decimal(($bindingWidth div 10) * $dpcm div $image-width) * 100,
xs:decimal(($bindingHeight div 10) * $dpcm div $image-height) * 100 )
else (
number((($surfaceWidth div 10) + 0.5) * $dpcm div $image-width) * 100,
number((($surfaceHeight div 10) + 0.5) * $dpcm div $image-height) * 100 )
xs:decimal((($surfaceWidth div 10) + 0.5) * $dpcm div $image-width) * 100,
xs:decimal((($surfaceHeight div 10) + 0.5) * $dpcm div $image-height) * 100 )
return if($type = 'total') then concat($scaler, $image, $resolution, '&mo=png')
else
string-join(($scaler, $image, "pct:" || string-join(($offset[1], $offset[2], $range[1], $range[2]), ","), string-join($resolution, ","), 0, "default.jpg" ), "/")
(: https://textgridlab.org/1.0/digilib/rest/IIIF/textgrid:164g9.1/pct:7.747474581830108,5.289308105687416,84.44747294194818,89.91823779668606/,1000/0/default.jpg:)
};
declare function transfo:KalenderblattSVG($id, $uri){
......
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