@@ -127,12 +127,10 @@ Snap.plugin(function (Snap, Element, Paper, global) {
127127 let rasterEl = marked [ i ] ;
128128 let bbox ;
129129 try {
130- bbox = rasterEl . get_total_bbox ( ) ;
131- } catch ( error ) {
132- console . warn (
133- `Getting bounding box for ${ rasterEl } failed.` ,
134- error
135- ) ;
130+ bbox = rasterEl . get_total_bbox ( ) ;
131+ }
132+ catch ( error ) {
133+ console . warn ( `Getting bounding box for ${ rasterEl } failed.` , error ) ;
136134 continue ;
137135 }
138136 // find overlaps
@@ -174,14 +172,13 @@ Snap.plugin(function (Snap, Element, Paper, global) {
174172 rasterEl . addClass ( `rasterCluster${ c } ` )
175173 ) ;
176174 let tmpSvg = svg . clone ( ) ;
177- tmpSvg . selectAll ( `.toRaster:not(.rasterCluster${ c } )` ) . remove ( ) ;
178- // tmpSvg.selectAll(`.toRaster:not(.rasterCluster${c})`).forEach((element) => {
179- // let elementToBeRemoved = tmpSvg.select('#' + element.attr('id'));
180- // let elementsToBeExcluded = ["text", "tspan"]
181- // if (elementToBeRemoved && !elementsToBeExcluded.includes(elementToBeRemoved.type)) {
182- // elementToBeRemoved.remove();
183- // }
184- // });
175+ tmpSvg . selectAll ( `.toRaster:not(.rasterCluster${ c } )` ) . forEach ( ( element ) => {
176+ let elementToBeRemoved = tmpSvg . select ( '#' + element . attr ( 'id' ) ) ;
177+ let elementsToBeExcluded = [ "text" , "tspan" ]
178+ if ( elementToBeRemoved && ! elementsToBeExcluded . includes ( elementToBeRemoved . type ) ) {
179+ elementToBeRemoved . remove ( ) ;
180+ }
181+ } ) ;
185182 // Fix IDs of filter references, those are not cloned correct (probably because reference is in style="..." definition)
186183 tmpSvg . fixIds ( "defs filter[mb\\:id]" , "mb:id" ) ; // namespace attribute selectors syntax: [ns\\:attrname]
187184 // DON'T fix IDs of textPath references, they're cloned correct.
@@ -338,17 +335,10 @@ Snap.plugin(function (Snap, Element, Paper, global) {
338335 // );
339336 }
340337
341- // only enlarge on fonts, images not necessary.
342- const doEnlargeBBox =
343- elem . selectAll ( "text" ) . filter ( ( e ) => {
344- const bb = e . getBBox ( ) ;
345- // this filter is required, as every quick text creates an empty text element (for switching between curved and straight text)
346- return bb . width > 0 && bb . height > 0 ;
347- } ) . length > 0 ;
348-
349- // Quick fix: in some browsers the bbox is too tight, so we just add an extra margin to all the sides, making the height and width larger in total
350- const enlargement_x = doEnlargeBBox ? 0.4 : 0 ; // percentage of the width added to each side
351- const enlargement_y = doEnlargeBBox ? 0.4 : 0 ; // percentage of the height added to each side
338+ // TODO only enlarge on images and fonts
339+ // Quick fix: in some browsers the bbox is too tight, so we just add an extra 10% to all the sides, making the height and width 20% larger in total
340+ const enlargement_x = 0.4 ; // percentage of the width added to each side
341+ const enlargement_y = 0.4 ; // percentage of the height added to each side
352342 const x1 = Math . max ( 0 , bbox . x - bbox . width * enlargement_x ) ;
353343 const x2 = Math . min ( wMM , bbox . x2 + bbox . width * enlargement_x ) ;
354344 const w = x2 - x1 ;
0 commit comments