Skip to content

Commit 9f410ae

Browse files
author
Adriano Barbosa
committed
fixing some isues to run in php 8
1 parent 485f26e commit 9f410ae

14 files changed

Lines changed: 396 additions & 25 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
vendor
2+
.vscode

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@
5151

5252
- Fixed bug: underlining would start but never end. Now it does.
5353
- Feature request: images are now filtered out of the output.
54+
55+
56+
### Update 5 Mai 28:
57+
58+
- fix declarations of dinamic properties to run in php8 environment
59+
- created some getters and setters and fix all the broken tests only

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "henck/rtf-html-php",
2+
"name": "barbosaadriano/rtf-html-php",
33
"description": "RTF to HTML converter in PHP",
44
"keywords": ["rtf", "converter"],
55
"type": "library",
@@ -9,14 +9,19 @@
99
{
1010
"name": "Alexander van Oostenrijk",
1111
"email": "alex.vanoostenrijk@gmail.com"
12+
},{
13+
"name": "Adriano Barbosa",
14+
"email": "b.adrianobarbosa@gmail.com"
1215
}
1316
],
1417
"scripts": {
1518
"test": [
1619
"phpunit tests"
1720
]
1821
},
19-
"require": {},
22+
"require": {
23+
"php": "^8.0"
24+
},
2025
"autoload": {
2126
"psr-4": {
2227
"RtfHtmlPhp\\": "src/"

index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use RtfHtmlPhp\Html\HtmlFormatter;
88

99
$original = file_get_contents("tests/rtf/hello-world.rtf");
10+
$original = file_get_contents("tests/rtf/fonts.rtf");
1011

1112
$document = new Document($original); // or use a string directly
1213
$formatter = new HtmlFormatter('UTF-8');
1314
$r = $formatter->Format($document);
1415
file_put_contents('rtf.html', $r);
15-
echo $r;
16-
?>
16+
echo $r;

rtf.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p><span style="font-family:Calibri;font-size:15px;">Hello, world.</span></p><p></p>
1+
<p><span style="font-family:Arial, sans-serif;font-size:15px;">Hello, world.</span></p><p></p>

src/Document.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
declare(strict_types=1);
44

55
namespace RtfHtmlPhp;
6-
#[\AllowDynamicProperties]
76
class Document
87
{
98
private $rtf; // RTF string being parsed
109
private $pos; // Current position in RTF string
1110
private $len; // Length of RTF string
1211
public $root = null; // Root group
1312
private $group; // Current RTF group
13+
private $char; //fixed dinamic declarations
14+
private $uc; //fixed dinamic declarations
1415

1516
public function __construct($rtf)
1617
{

src/Html/Font.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Font
88
public $name;
99
public $charset;
1010
public $codepage;
11+
public $fprq;
1112

1213
public function toStyle(): string {
1314
$list = array();

src/Html/HtmlFormatter.php

Lines changed: 168 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@
44

55
use RtfHtmlPhp\Document;
66

7-
#[\AllowDynamicProperties]
87
class HtmlFormatter
98
{
109
private $output = '';
1110
private $encoding;
1211
private $defaultFont;
1312

13+
// dinamic declarations fixed
14+
15+
private $previousState;
16+
private $states;
17+
/**
18+
* State
19+
*/
20+
private $state;
21+
private $openedTags;
22+
private $RTFencoding;
23+
24+
1425
// By default, HtmlFormatter uses HTML_ENTITIES for code conversion.
1526
// You can optionally support a different endoing when creating
1627
// the HtmlFormatter instance.
@@ -117,7 +128,7 @@ protected function LoadFont(\RtfHtmlPhp\Group $fontGroup) {
117128
*/
118129
}
119130

120-
State::SetFont($fontNumber, $font);
131+
State::setFontInFontTable($fontNumber, $font);
121132
}
122133

123134
protected function ExtractFontTable($fontTblGrp)
@@ -274,28 +285,28 @@ protected function FormatControlWord($word)
274285
*/
275286

276287
case 'b': // bold
277-
$this->state->bold = $word->parameter;
288+
$this->state->setBold($word->parameter);
278289
break;
279290
case 'i': // italic
280-
$this->state->italic = $word->parameter;
291+
$this->state->setItalic($word->parameter);
281292
break;
282293
case 'ul': // underline
283-
$this->state->underline = $word->parameter;
294+
$this->state->setUnderline($word->parameter);
284295
break;
285296
case 'ulnone': // no underline
286-
$this->state->underline = false;
297+
$this->state->setUnderline(false);
287298
break;
288299
case 'strike': // strike-through
289-
$this->state->strike = $word->parameter;
300+
$this->state->setStrike($word->parameter);
290301
break;
291302
case 'v': // hidden
292-
$this->state->hidden = $word->parameter;
303+
$this->state->setHidden($word->parameter);
293304
break;
294305
case 'fs': // Font size
295-
$this->state->fontsize = ceil(($word->parameter / 24) * 16);
306+
$this->state->setFontsize(ceil(($word->parameter / 24) * 16));
296307
break;
297308
case 'f': // Font
298-
$this->state->font = $word->parameter;
309+
$this->state->setFont($word->parameter);
299310
break;
300311
case 'deff': // Store default font
301312
$this->defaultFont = $word->parameter;
@@ -307,14 +318,14 @@ protected function FormatControlWord($word)
307318

308319
case 'cf':
309320
case 'chcfpat':
310-
$this->state->fontcolor = $word->parameter;
321+
$this->state->setFontcolor($word->parameter);
311322
break;
312323
case 'cb':
313324
case 'chcbpat':
314-
$this->state->background = $word->parameter;
325+
$this->state->setBackground($word->parameter);
315326
break;
316327
case 'highlight':
317-
$this->state->hcolor = $word->parameter;
328+
$this->state->setHcolor($word->parameter);
318329
break;
319330

320331
/*
@@ -595,5 +606,149 @@ protected function ord_utf8($chr)
595606

596607
trigger_error("Invalid Unicode character: {$chr}");
597608
}
609+
610+
/**
611+
* Get the value of output
612+
*/
613+
public function getOutput()
614+
{
615+
return $this->output;
616+
}
617+
618+
/**
619+
* Set the value of output
620+
*/
621+
public function setOutput($output): self
622+
{
623+
$this->output = $output;
624+
625+
return $this;
626+
}
627+
628+
/**
629+
* Get the value of encoding
630+
*/
631+
public function getEncoding()
632+
{
633+
return $this->encoding;
634+
}
635+
636+
/**
637+
* Set the value of encoding
638+
*/
639+
public function setEncoding($encoding): self
640+
{
641+
$this->encoding = $encoding;
642+
643+
return $this;
644+
}
645+
646+
/**
647+
* Get the value of defaultFont
648+
*/
649+
public function getDefaultFont()
650+
{
651+
return $this->defaultFont;
652+
}
653+
654+
/**
655+
* Set the value of defaultFont
656+
*/
657+
public function setDefaultFont($defaultFont): self
658+
{
659+
$this->defaultFont = $defaultFont;
660+
661+
return $this;
662+
}
663+
664+
/**
665+
* Get the value of previousState
666+
*/
667+
public function getPreviousState()
668+
{
669+
return $this->previousState;
670+
}
671+
672+
/**
673+
* Set the value of previousState
674+
*/
675+
public function setPreviousState($previousState): self
676+
{
677+
$this->previousState = $previousState;
678+
679+
return $this;
680+
}
681+
682+
/**
683+
* Get the value of states
684+
*/
685+
public function getStates()
686+
{
687+
return $this->states;
688+
}
689+
690+
/**
691+
* Set the value of states
692+
*/
693+
public function setStates($states): self
694+
{
695+
$this->states = $states;
696+
697+
return $this;
698+
}
699+
700+
/**
701+
* Get the value of state
702+
*/
703+
public function getState()
704+
{
705+
return $this->state;
706+
}
707+
708+
/**
709+
* Set the value of state
710+
*/
711+
public function setState($state): self
712+
{
713+
$this->state = $state;
714+
715+
return $this;
716+
}
717+
718+
/**
719+
* Get the value of openedTags
720+
*/
721+
public function getOpenedTags()
722+
{
723+
return $this->openedTags;
724+
}
725+
726+
/**
727+
* Set the value of openedTags
728+
*/
729+
public function setOpenedTags($openedTags): self
730+
{
731+
$this->openedTags = $openedTags;
732+
733+
return $this;
734+
}
735+
736+
/**
737+
* Get the value of RTFencoding
738+
*/
739+
public function getRTFencoding()
740+
{
741+
return $this->RTFencoding;
742+
}
743+
744+
/**
745+
* Set the value of RTFencoding
746+
*/
747+
public function setRTFencoding($RTFencoding): self
748+
{
749+
$this->RTFencoding = $RTFencoding;
750+
751+
return $this;
752+
}
598753
}
599754

src/Html/Image.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
class Image
66
{
7+
8+
public $format;
9+
public $width;
10+
public $height;
11+
public $goalWidth;
12+
public $goalHeight;
13+
public $pcScaleX;
14+
public $pcScaleY;
15+
public $binarySize;
16+
public $ImageData;
17+
718
public function __construct()
819
{
920
$this->Reset();

0 commit comments

Comments
 (0)