javascript - How can I get all text in an SVG document that's exactly within a rectangular region? -
i have complex svg document generated pdf research paper via pdf.js, , want find text within rectangular area. in support of web-based labeling tool users can draw rectangles on top of arbitrary regions of rendered svg file (basically treating image) , need see corresponding text. first approach thought of iterating through each of svg's svg:text
or svg:tspan
elements , checking whether intersects rectangle in question, perhaps using checkenclosure() (unsupported ff, btw).
however, won't work cases rectangle annotates characters subset of svg:text
or svg:tspan
. example, imagine want annotate individual keywords in line:
keywords: heusler alloys; pressure effect; curie temperature
the svg in case breaks 2 's (because 'keywords ' italics):
'keywords: '
and
'heusler alloys; pressure effect; curie temperature'
if 1 rect drawn around words 'pressure effect', program need scan each character in each , intersection rect (more specifically, contained it). in way treat each char rectangular glyph.
it if share pointers, either based on initial approach or on else know about.
update 2015-07-23:
following w3 svg dom methods of interest find:
interfacesvgsvgelement - interface corresponds ‘svg’ element
- boolean checkenclosure(in svgelement element, in svgrect rect)
- boolean checkintersection(in svgelement element, in svgrect rect)
- nodelist getenclosurelist(in svgrect rect, in svgelement referenceelement)
- nodelist getintersectionlist(in svgrect rect, in svgelement referenceelement)
interfacesvgtextcontentelement - inherited various text-related interfaces, such svgtextelement, svgtspanelement, svgtrefelement, svgaltglyphelement , svgtextpathelement.
- svgrect getextentofchar(in unsigned long charnum);
interfacesvglocatable - for elements either have ‘transform’ attribute or don't have ‘transform’ attribute content can have bounding box in current user space
- svgrect getbbox()
Comments
Post a Comment