alihassan143 / htmltopdfwidgets

Html To Pdf
https://pub.dev/packages/htmltopdfwidgets
Apache License 2.0
12 stars 18 forks source link

Update html_to_widgets.dart + css #9

Closed Ammarmahmoud1995 closed 7 months ago

Ammarmahmoud1995 commented 1 year ago

I added support to Css( font size , direction , color, line break ) this mainly help me with html enhanced editor

alihassan143 commented 1 year ago

@Ammarmahmoud1995 also create issue for that

Ammarmahmoud1995 commented 1 year ago

I commit the changes , hope I didn't miss something
With all regards

alihassan143 commented 1 year ago

@Ammarmahmoud1995 i did some changes kindly add some test related to your function please

Ammarmahmoud1995 commented 1 year ago

So I did some unit testing in flutter test covered 6 cases ,,, I used records in expect function ... am not sure if this is exactly what you are looking for .. hope it is useful

List input = ['''<div dir="rtl" style="text-align: left;"><font color="#c437c4" size="5">Ammar mahmoud 1</font></div>''',
'''<div dir="rtl" style="text-align: left;"><font color="#c437c4" size="5"><br></font></div>''',
'''<div dir="rtl" style="text-align: center;"><font size="6">2 عمار محمود&nbsp;</font></div>''',
'''<div dir="rtl" style="text-align: center;"><font size="6"><br></font></div>''',
'''<div dir="rtl" style="text-align: center;"><font color="#583f3e" size="6">3 عمار Mahmoud</font></div>''',
'''<div dir="rtl" style="text-align: right;">4 السلام وعليكم</div>'''
] ;
List expectedValue = [CssProberties(fontsize: 18.0,alignmentfortext: Alignment.centerLeft,selectedcolor:PdfColor(0.7686274509803922, 0.21568627450980393, 0.7686274509803922, 1)),
CssProberties(fontsize: 18.0,alignmentfortext: Alignment.centerLeft,selectedcolor:PdfColor(0.7686274509803922, 0.21568627450980393, 0.7686274509803922, 1) ),
CssProberties(fontsize: 24.0,alignmentfortext: Alignment.center,selectedcolor:null ),
CssProberties(fontsize: 24.0,alignmentfortext: Alignment.center,selectedcolor:null ),
CssProberties(fontsize: 24.0,alignmentfortext: Alignment.center,selectedcolor:PdfColor(0.34509803921568627, 0.24705882352941178, 0.24313725490196078, 1), ),
CssProberties(fontsize: null,alignmentfortext: Alignment.centerRight,selectedcolor:null ),
]  ;
void main() {    
   for(int i = 0 ; i<input.length ; i ++) {
   test("test _handleCss",(){  
      var expected = expectedValue[i];     
  (double?,Alignment?,PdfColor?)  expectedrecord = (expected.fontsize,expected.alignmentfortext,expected.selectedcolor)  ; 
      var actual = _handleCss(input[i]);   
 (double?,Alignment?,PdfColor?)  actualRecord = (actual.fontsize,actual.alignmentfortext,actual.selectedcolor)  ; 
      expect(actualRecord,expectedrecord); 
   }); }
}
Ammarmahmoud1995 commented 1 year ago

Results where 6 ✓ test _handleCss Multiple tests named "test _handleCss" ran but only one was expected. You may have multiple tests with the same name. Exited

alihassan143 commented 1 year ago

@Ammarmahmoud1995 kindly write inside test folder so ci can check it

alihassan143 commented 1 year ago

@Ammarmahmoud1995 also remove the conflicts