@@ -136,6 +136,36 @@ public void Parse_AnchorDrawingWithDiamondShape_ReturnsDrawingShapeRunElement()
136136 shape . PresetKind . ToString ( ) . Should ( ) . Be ( "Diamond" ) ;
137137 }
138138
139+ [ Fact ]
140+ public void Parse_InlineDrawingWithDrawingMlTextFrame_ExtractsText ( )
141+ {
142+ var drawing = CreateInlineShapeWithTextBody ( "rect" , 914400L , 457200L , [ "First line" , "Second line" ] ) ;
143+ var run = new Run ( drawing ) ;
144+
145+ var elements = RunElementParser . Parse ( run ) ;
146+
147+ var shape = elements . Should ( ) . ContainSingle ( )
148+ . Which . Should ( ) . BeOfType < DrawingShapeRunElement > ( )
149+ . Subject ;
150+ shape . TextFrame . HasTextFrame . Should ( ) . BeTrue ( ) ;
151+ shape . TextFrame . Text . Should ( ) . Be ( "First line\n Second line" ) ;
152+ }
153+
154+ [ Fact ]
155+ public void Parse_InlineDrawingWithWordTextBoxContent_ExtractsText ( )
156+ {
157+ var drawing = CreateInlineShapeWithTextBoxContent ( "rect" , 914400L , 457200L , [ "Box line one" , "Box line two" ] ) ;
158+ var run = new Run ( drawing ) ;
159+
160+ var elements = RunElementParser . Parse ( run ) ;
161+
162+ var shape = elements . Should ( ) . ContainSingle ( )
163+ . Which . Should ( ) . BeOfType < DrawingShapeRunElement > ( )
164+ . Subject ;
165+ shape . TextFrame . HasTextFrame . Should ( ) . BeTrue ( ) ;
166+ shape . TextFrame . Text . Should ( ) . Be ( "Box line one\n Box line two" ) ;
167+ }
168+
139169 // -------------------------------------------------------------------------
140170 // Helpers
141171 // -------------------------------------------------------------------------
@@ -204,4 +234,59 @@ private static Drawing CreateAnchorShape(string presetName, long widthEmu, long
204234 } ;
205235 return new Drawing ( anchor ) ;
206236 }
237+
238+ private static Drawing CreateInlineShapeWithTextBody ( string presetName , long widthEmu , long heightEmu , IReadOnlyList < string > lines )
239+ {
240+ var presetGeom = new A . PresetGeometry ( ) ;
241+ presetGeom . SetAttribute ( new OpenXmlAttribute ( "prst" , string . Empty , presetName ) ) ;
242+ var textBody = new OpenXmlUnknownElement ( "txBody" )
243+ {
244+ InnerXml = "<bodyPr/>" + string . Concat ( lines . Select ( line => $ "<p><r><t>{ System . Security . SecurityElement . Escape ( line ) } </t></r></p>") )
245+ } ;
246+ var spPr = new A . ShapeProperties ( presetGeom ) ;
247+ var graphicData = new A . GraphicData ( spPr , textBody )
248+ {
249+ Uri = "http://schemas.openxmlformats.org/drawingml/2006/main"
250+ } ;
251+ var graphic = new A . Graphic ( graphicData ) ;
252+ var inline = new DW . Inline (
253+ new DW . Extent { Cx = widthEmu , Cy = heightEmu } ,
254+ graphic )
255+ {
256+ DistanceFromTop = 0 ,
257+ DistanceFromBottom = 0 ,
258+ DistanceFromLeft = 0 ,
259+ DistanceFromRight = 0
260+ } ;
261+ return new Drawing ( inline ) ;
262+ }
263+
264+ private static Drawing CreateInlineShapeWithTextBoxContent ( string presetName , long widthEmu , long heightEmu , IReadOnlyList < string > lines )
265+ {
266+ var presetGeom = new A . PresetGeometry ( ) ;
267+ presetGeom . SetAttribute ( new OpenXmlAttribute ( "prst" , string . Empty , presetName ) ) ;
268+ var textBox = new OpenXmlUnknownElement ( "wps:txbx" )
269+ {
270+ InnerXml = "<w:txbxContent xmlns:w=\" http://schemas.openxmlformats.org/wordprocessingml/2006/main\" >"
271+ + string . Concat ( lines . Select ( line => $ "<w:p><w:r><w:t>{ System . Security . SecurityElement . Escape ( line ) } </w:t></w:r></w:p>") )
272+ + "</w:txbxContent>"
273+ } ;
274+ var spPr = new A . ShapeProperties ( presetGeom ) ;
275+ var graphicData = new A . GraphicData ( spPr , textBox )
276+ {
277+ Uri = "http://schemas.openxmlformats.org/drawingml/2006/main"
278+ } ;
279+ var graphic = new A . Graphic ( graphicData ) ;
280+ var inline = new DW . Inline (
281+ new DW . Extent { Cx = widthEmu , Cy = heightEmu } ,
282+ graphic )
283+ {
284+ DistanceFromTop = 0 ,
285+ DistanceFromBottom = 0 ,
286+ DistanceFromLeft = 0 ,
287+ DistanceFromRight = 0
288+ } ;
289+ return new Drawing ( inline ) ;
290+ }
291+
207292}
0 commit comments