@@ -104,16 +104,17 @@ impl BuildXML for Drawing {
104104 b = b. align ( & x. to_string ( ) ) . close ( ) ;
105105 }
106106 }
107- if let DrawingPosition :: Offset ( x) = p. position_h {
108- let x = format ! ( "{}" , x as u32 ) ;
109- b = b. pos_offset ( & x) . close ( ) ;
110- }
111107
112108 b = b. open_position_v ( & format ! ( "{}" , p. relative_from_v) ) ;
113109
114- if let DrawingPosition :: Offset ( y) = p. position_v {
115- let y = format ! ( "{}" , y as u32 ) ;
116- b = b. pos_offset ( & y) . close ( ) ;
110+ match p. position_v {
111+ DrawingPosition :: Offset ( y) => {
112+ let y = format ! ( "{}" , y as u32 ) ;
113+ b = b. pos_offset ( & y) . close ( ) ;
114+ }
115+ DrawingPosition :: Align ( a) => {
116+ b = b. align ( & a. to_string ( ) ) . close ( ) ;
117+ }
117118 }
118119 }
119120
@@ -316,6 +317,69 @@ mod tests {
316317</pic:pic></a:graphicData>
317318 </a:graphic>
318319 </wp:anchor>
320+ </w:drawing>"#
321+ ) ;
322+ }
323+
324+ #[ test]
325+ fn test_issue686 ( ) {
326+ use std:: io:: Read ;
327+
328+ let mut img = std:: fs:: File :: open ( "../images/cat_min.jpg" ) . unwrap ( ) ;
329+ let mut buf = Vec :: new ( ) ;
330+ let _ = img. read_to_end ( & mut buf) . unwrap ( ) ;
331+ let pic = Pic :: new ( & buf)
332+ . size ( 320 * 9525 , 240 * 9525 )
333+ . floating ( )
334+ . offset_x ( 300 * 9525 )
335+ . offset_y ( 400 * 9525 ) ;
336+
337+ let d = Drawing :: new ( ) . pic ( pic) . build ( ) ;
338+ assert_eq ! (
339+ str :: from_utf8( & d) . unwrap( ) ,
340+ r#"<w:drawing>
341+ <wp:anchor distT="0" distB="0" distL="0" distR="0" simplePos="0" allowOverlap="0" behindDoc="0" locked="0" layoutInCell="0" relativeHeight="190500">
342+ <wp:simplePos x="0" y="0" />
343+ <wp:positionH relativeFrom="margin">
344+ <wp:posOffset>2857500</wp:posOffset>
345+ </wp:positionH>
346+ <wp:positionV relativeFrom="margin">
347+ <wp:posOffset>3810000</wp:posOffset>
348+ </wp:positionV>
349+ <wp:extent cx="3048000" cy="2286000" />
350+ <wp:effectExtent b="0" l="0" r="0" t="0" />
351+ <wp:wrapSquare wrapText="bothSides" />
352+ <wp:docPr id="1" name="Figure" />
353+ <wp:cNvGraphicFramePr>
354+ <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1" />
355+ </wp:cNvGraphicFramePr>
356+ <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
357+ <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
358+ <pic:nvPicPr>
359+ <pic:cNvPr id="0" name="" />
360+ <pic:cNvPicPr>
361+ <a:picLocks noChangeAspect="1" noChangeArrowheads="1" />
362+ </pic:cNvPicPr>
363+ </pic:nvPicPr>
364+ <pic:blipFill>
365+ <a:blip r:embed="rIdImage123" />
366+ <a:srcRect />
367+ <a:stretch>
368+ <a:fillRect />
369+ </a:stretch>
370+ </pic:blipFill>
371+ <pic:spPr bwMode="auto">
372+ <a:xfrm rot="0">
373+ <a:off x="0" y="0" />
374+ <a:ext cx="3048000" cy="2286000" />
375+ </a:xfrm>
376+ <a:prstGeom prst="rect">
377+ <a:avLst />
378+ </a:prstGeom>
379+ </pic:spPr>
380+ </pic:pic></a:graphicData>
381+ </a:graphic>
382+ </wp:anchor>
319383</w:drawing>"#
320384 ) ;
321385 }
0 commit comments