@@ -21,6 +21,13 @@ internal class OwDocument
2121 private MemoryStream _ms ;
2222 private PKG . MainDocumentPart _mainPart ;
2323 private readonly object _lockObject = new object ( ) ;
24+ public enum ParagraphAlignment
25+ {
26+ Left ,
27+ Center ,
28+ Right ,
29+ Justify
30+ }
2431 private OwDocument ( )
2532 {
2633 lock ( _lockObject )
@@ -130,6 +137,37 @@ internal WP.Paragraph CreateParagraph(FF.Paragraph ffP)
130137 var paragraphProperties = new WP . ParagraphProperties ( ) ;
131138 var paragraphStyleId = new WP . ParagraphStyleId { Val = ffP . Style } ;
132139 paragraphProperties . Append ( paragraphStyleId ) ;
140+
141+ if ( Enum . TryParse < ParagraphAlignment > ( ffP . Alignment , true , out var alignmentEnum ) )
142+ {
143+ WP . JustificationValues justificationValue = MapAlignmentToJustification ( alignmentEnum ) ;
144+ paragraphProperties . Append ( new WP . Justification { Val = justificationValue } ) ;
145+ }
146+
147+ if ( ffP . Indentation != null )
148+ {
149+ SetIndentation ( paragraphProperties , ffP . Indentation ) ;
150+ }
151+
152+ if ( ffP . IsNumbered )
153+ {
154+ var numberingProperties = new WP . NumberingProperties
155+ {
156+ NumberingId = new WP . NumberingId { Val = ffP . NumberingId } ,
157+ NumberingLevelReference = new WP . NumberingLevelReference { Val = ffP . NumberingLevel . Value }
158+ } ;
159+ paragraphProperties . Append ( numberingProperties ) ;
160+ }
161+
162+ if ( ffP . IsBullet )
163+ {
164+ var bulletProperties = new WP . NumberingProperties
165+ {
166+ NumberingId = new WP . NumberingId { Val = 1 } ,
167+ NumberingLevelReference = new WP . NumberingLevelReference { Val = 0 }
168+ } ;
169+ paragraphProperties . Append ( bulletProperties ) ;
170+ }
133171 wpParagraph . Append ( paragraphProperties ) ;
134172 }
135173
@@ -194,6 +232,50 @@ internal WP.Paragraph CreateParagraph(FF.Paragraph ffP)
194232 }
195233 }
196234
235+ private void SetIndentation ( WP . ParagraphProperties paragraphProperties , FF . Indentation ffIndentation )
236+ {
237+ var indentation = new WP . Indentation ( ) ;
238+
239+ if ( ffIndentation . Left > 0 )
240+ {
241+ indentation . Left = ( ffIndentation . Left * 1440 ) . ToString ( ) ;
242+ }
243+
244+ if ( ffIndentation . Right > 0 )
245+ {
246+ indentation . Right = ( ffIndentation . Right * 1440 ) . ToString ( ) ;
247+ }
248+
249+ if ( ffIndentation . FirstLine > 0 )
250+ {
251+ indentation . FirstLine = ( ffIndentation . FirstLine * 1440 ) . ToString ( ) ;
252+ }
253+
254+ if ( ffIndentation . Hanging > 0 )
255+ {
256+ indentation . Hanging = ( ffIndentation . Hanging * 1440 ) . ToString ( ) ;
257+ }
258+
259+ paragraphProperties . Append ( indentation ) ;
260+ }
261+
262+ private WP . JustificationValues MapAlignmentToJustification ( ParagraphAlignment alignment )
263+ {
264+ switch ( alignment )
265+ {
266+ case ParagraphAlignment . Left :
267+ return WP . JustificationValues . Left ;
268+ case ParagraphAlignment . Center :
269+ return WP . JustificationValues . Center ;
270+ case ParagraphAlignment . Right :
271+ return WP . JustificationValues . Right ;
272+ case ParagraphAlignment . Justify :
273+ return WP . JustificationValues . Both ;
274+ default :
275+ return WP . JustificationValues . Left ;
276+ }
277+ }
278+
197279 internal WP . Table CreateTable ( FF . Table ffTable )
198280 {
199281 lock ( _lockObject )
@@ -458,7 +540,41 @@ internal FF.Paragraph LoadParagraph(WP.Paragraph wpPara, int id)
458540 if ( paraStyleId != null )
459541 {
460542 if ( paraStyleId . Val != null ) ffP . Style = paraStyleId . Val . Value ;
543+
544+ if ( IsBulletStyle ( paraStyleId . Val . Value ) )
545+ {
546+ ffP . IsBullet = true ;
547+ }
461548 }
549+ var numberingProperties = paraProps . Elements < WP . NumberingProperties > ( ) . FirstOrDefault ( ) ;
550+ if ( numberingProperties != null )
551+ {
552+ ffP . IsNumbered = true ;
553+ ffP . NumberingId = numberingProperties . NumberingId ? . Val ?? 0 ;
554+ ffP . NumberingLevel = numberingProperties . NumberingLevelReference ? . Val ?? 0 ;
555+ }
556+ }
557+ var justificationElement = paraProps . Elements < WP . Justification > ( ) . FirstOrDefault ( ) ;
558+ if ( justificationElement != null )
559+ {
560+ ffP . Alignment = MapJustificationToAlignment ( justificationElement . Val ) ;
561+ }
562+ var Indentation = paraProps . Elements < WP . Indentation > ( ) . FirstOrDefault ( ) ;
563+ if ( Indentation . Left != null )
564+ {
565+ ffP . Indentation . Left = int . Parse ( Indentation . Left ) ;
566+ }
567+ if ( Indentation . Right != null )
568+ {
569+ ffP . Indentation . Right = int . Parse ( Indentation . Right ) ;
570+ }
571+ if ( Indentation . Hanging != null )
572+ {
573+ ffP . Indentation . Hanging = int . Parse ( Indentation . Hanging ) ;
574+ }
575+ if ( Indentation . FirstLine != null )
576+ {
577+ ffP . Indentation . FirstLine = int . Parse ( Indentation . FirstLine ) ;
462578 }
463579
464580 var runs = wpPara . Elements < WP . Run > ( ) ;
@@ -473,7 +589,7 @@ internal FF.Paragraph LoadParagraph(WP.Paragraph wpPara, int id)
473589 {
474590 Text = wpR . InnerText ,
475591 FontFamily = wpR . RunProperties ? . RunFonts ? . Ascii ?? null ,
476- FontSize = fontSize ?? 0 , //int.Parse(wpR.RunProperties?.FontSize?.Val ?? null),
592+ FontSize = fontSize ?? 0 ,
477593 Color = wpR . RunProperties ? . Color ? . Val ?? null ,
478594 Bold = ( wpR . RunProperties != null && wpR . RunProperties . Bold != null ) ,
479595 Italic = ( wpR . RunProperties != null && wpR . RunProperties . Italic != null ) ,
@@ -492,6 +608,28 @@ internal FF.Paragraph LoadParagraph(WP.Paragraph wpPara, int id)
492608 }
493609 }
494610
611+ private bool IsBulletStyle ( string styleId )
612+ {
613+ return styleId == "BulletStyle" ;
614+ }
615+
616+ private string MapJustificationToAlignment ( WP . JustificationValues justificationValue )
617+ {
618+ switch ( justificationValue )
619+ {
620+ case WP . JustificationValues . Left :
621+ return "Left" ;
622+ case WP . JustificationValues . Center :
623+ return "Center" ;
624+ case WP . JustificationValues . Right :
625+ return "Right" ;
626+ case WP . JustificationValues . Both :
627+ return "Justify" ;
628+ default :
629+ return "Left" ;
630+ }
631+ }
632+
495633 internal FF . Image LoadImage ( WP . Drawing drawing , int sequence )
496634 {
497635 lock ( _lockObject )
0 commit comments