Skip to content

Commit 89ea480

Browse files
committed
minor changes
1 parent 365568c commit 89ea480

File tree

6 files changed

+70
-65
lines changed

6 files changed

+70
-65
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.0.4
2+
* Fix wrong styles of background color ([#31](https://github.com/alihassan143/htmltopdfwidgets/issues/31))
3+
* Add support for custom fonts ([#34](https://github.com/alihassan143/htmltopdfwidgets/pull/34)) by @hig-dev
14
## 1.0.3
25
* Intial support for checkboxes
36
*([#25](https://github.com/alihassan143/htmltopdfwidgets/issues/25))

example/pubspec.lock

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
44
archive:
5-
dependency: transitive
5+
dependency: "direct overridden"
66
description:
77
name: archive
8-
sha256: "22600aa1e926be775fa5fe7e6894e7fb3df9efda8891c73f70fb3262399a432d"
8+
sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "3.4.10"
11+
version: "3.6.1"
1212
async:
1313
dependency: transitive
1414
description:
@@ -41,14 +41,6 @@ packages:
4141
url: "https://pub.dev"
4242
source: hosted
4343
version: "1.18.0"
44-
convert:
45-
dependency: transitive
46-
description:
47-
name: convert
48-
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
49-
url: "https://pub.dev"
50-
source: hosted
51-
version: "3.1.1"
5244
crypto:
5345
dependency: transitive
5446
description:
@@ -69,10 +61,10 @@ packages:
6961
dependency: "direct dev"
7062
description:
7163
name: flutter_lints
72-
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
64+
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
7365
url: "https://pub.dev"
7466
source: hosted
75-
version: "2.0.3"
67+
version: "4.0.0"
7668
html:
7769
dependency: transitive
7870
description:
@@ -87,15 +79,15 @@ packages:
8779
path: ".."
8880
relative: true
8981
source: path
90-
version: "1.0.2"
82+
version: "1.0.4"
9183
http:
9284
dependency: transitive
9385
description:
9486
name: http
95-
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
87+
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
9688
url: "https://pub.dev"
9789
source: hosted
98-
version: "1.2.0"
90+
version: "1.2.2"
9991
http_parser:
10092
dependency: transitive
10193
description:
@@ -112,22 +104,14 @@ packages:
112104
url: "https://pub.dev"
113105
source: hosted
114106
version: "4.1.4"
115-
js:
116-
dependency: transitive
117-
description:
118-
name: js
119-
sha256: "4186c61b32f99e60f011f7160e32c89a758ae9b1d0c6d28e2c02ef0382300e2b"
120-
url: "https://pub.dev"
121-
source: hosted
122-
version: "0.7.0"
123107
lints:
124108
dependency: transitive
125109
description:
126110
name: lints
127-
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
111+
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
128112
url: "https://pub.dev"
129113
source: hosted
130-
version: "2.1.1"
114+
version: "4.0.0"
131115
meta:
132116
dependency: transitive
133117
description:
@@ -156,10 +140,10 @@ packages:
156140
dependency: transitive
157141
description:
158142
name: pdf
159-
sha256: "93cbb2c06de9bab91844550f19896b2373e7a5ce25173995e7e5ec5e1741429d"
143+
sha256: "05df53f8791587402493ac97b9869d3824eccbc77d97855f4545cf72df3cae07"
160144
url: "https://pub.dev"
161145
source: hosted
162-
version: "3.10.7"
146+
version: "3.11.1"
163147
petitparser:
164148
dependency: transitive
165149
description:
@@ -168,14 +152,6 @@ packages:
168152
url: "https://pub.dev"
169153
source: hosted
170154
version: "6.0.2"
171-
pointycastle:
172-
dependency: transitive
173-
description:
174-
name: pointycastle
175-
sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
176-
url: "https://pub.dev"
177-
source: hosted
178-
version: "3.7.4"
179155
qr:
180156
dependency: transitive
181157
description:
@@ -228,10 +204,10 @@ packages:
228204
dependency: transitive
229205
description:
230206
name: web
231-
sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05"
207+
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
232208
url: "https://pub.dev"
233209
source: hosted
234-
version: "0.4.2"
210+
version: "1.0.0"
235211
xml:
236212
dependency: transitive
237213
description:
@@ -241,4 +217,4 @@ packages:
241217
source: hosted
242218
version: "6.5.0"
243219
sdks:
244-
dart: ">=3.2.0 <4.0.0"
220+
dart: ">=3.4.0 <4.0.0"

example/pubspec.yaml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
name: example
2-
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
2+
publish_to: "none" # Remove this line if you wish to publish to pub.dev
33
version: 1.0.0+1
44

55
environment:
6-
sdk: '>=3.0.3 <4.0.0'
7-
6+
sdk: ">=3.0.3 <4.0.0"
87

98
dependencies:
10-
11-
12-
13-
149
htmltopdfwidgets:
1510
path: ../
16-
11+
dependency_overrides:
12+
archive: 3.6.1
1713
dev_dependencies:
18-
19-
20-
21-
flutter_lints: ^2.0.0
14+
flutter_lints: ^4.0.0

lib/src/extension/color_extension.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ extension ColorExtension on PdfColor {
4040
String toRgbaString() {
4141
return 'rgba($red, $green, $blue, $alpha)';
4242
}
43+
44+
static PdfColor hexToPdfColor(String hexColor) {
45+
// Remove the leading '#' if it exists
46+
hexColor = hexColor.replaceAll('#', '');
47+
48+
// Ensure the hex string is in the correct format (6 characters long)
49+
if (hexColor.length == 3) {
50+
hexColor = hexColor.split('').map((char) => '$char$char').join();
51+
}
52+
53+
if (hexColor.length != 6) {
54+
throw ArgumentError('Invalid hex color format');
55+
}
56+
57+
// Convert hex string to integer values for RGB
58+
final int red = int.parse(hexColor.substring(0, 2), radix: 16);
59+
final int green = int.parse(hexColor.substring(2, 4), radix: 16);
60+
final int blue = int.parse(hexColor.substring(4, 6), radix: 16);
61+
62+
// Return a PdfColor object using the RGB values (normalized to 0-1)
63+
return PdfColor.fromInt((red << 16) | (green << 8) | blue);
64+
}
4365
}
4466

4567
// Function to calculate the hex representation of an RGBA color.
@@ -59,3 +81,17 @@ int hexOfRGBA(int r, int g, int b, {double opacity = 1}) {
5981
return int.parse(
6082
'0x${a.toRadixString(16)}${r.toRadixString(16)}${g.toRadixString(16)}${b.toRadixString(16)}');
6183
}
84+
85+
bool isRgba(String color) {
86+
// Regular expression to check if the color is in 'rgba' format
87+
final rgbaRegex = RegExp(r"^rgba?\((\s*\d+\s*,){2,3}\s*\d+(\.\d+)?\s*\)$",
88+
caseSensitive: false);
89+
return rgbaRegex.hasMatch(color);
90+
}
91+
92+
bool isHex(String color) {
93+
// Regular expression to check if the color is in hex format (#RRGGBB or #RGB)
94+
final hexRegex =
95+
RegExp(r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", caseSensitive: false);
96+
return hexRegex.hasMatch(color);
97+
}

lib/src/html_to_widgets.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22
import 'dart:collection';
3+
import 'dart:convert';
34
import 'dart:typed_data';
45

56
import 'package:html/dom.dart' as dom;
@@ -15,7 +16,6 @@ import 'html_tags.dart';
1516
import 'pdfwidgets/bullet_list.dart';
1617
import 'pdfwidgets/number_list.dart';
1718
import 'pdfwidgets/quote_widget.dart';
18-
import 'dart:convert';
1919

2020
////html deocoder that deocde html and convert it into pdf widgets
2121
class WidgetsHTMLDecoder {
@@ -758,7 +758,9 @@ class WidgetsHTMLDecoder {
758758
final backgroundColorStr = cssMap["background-color"];
759759
final backgroundColor = backgroundColorStr == null
760760
? null
761-
: ColorExtension.tryFromRgbaString(backgroundColorStr);
761+
: isHex(backgroundColorStr)
762+
? ColorExtension.hexToPdfColor(backgroundColorStr)
763+
: ColorExtension.tryFromRgbaString(backgroundColorStr);
762764
if (backgroundColor != null) {
763765
style = style.copyWith(color: backgroundColor);
764766
}

pubspec.yaml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
name: htmltopdfwidgets
22
description: Htmlt to pdf widgets library convert html text to pdf widgets
3-
version: 1.0.3
3+
version: 1.0.4
44
homepage: https://github.com/alihassan143/htmltopdfwidgets
55

66
environment:
77
sdk: ">=3.0.0 <4.0.0"
88

99
dependencies:
10-
pdf: ">=3.10.3 <4.0.0"
11-
html: ">=0.15.3 <1.0.0"
12-
http: ">=0.13.1 <2.0.0"
13-
dependency_overrides:
14-
pdf:
15-
git:
16-
url: https://github.com/DavBfr/dart_pdf.git
17-
path: pdf/
18-
ref: master
10+
pdf: ">=3.11.1 <4.0.0"
11+
html: ">=0.15.4 <1.0.0"
12+
http: ">=1.2.2 <2.0.0"
13+
1914
dev_dependencies:
20-
flutter_lints: ^2.0.0
21-
lints: ^2.1.1
15+
flutter_lints: ^4.0.0
16+
lints: ^4.0.0
2217
test: ">=1.16.0 <2.0.0"

0 commit comments

Comments
 (0)