Add support for pixel based font sizes (vB 5)
authorTim Düsterhus <tim@bastelstu.be>
Sat, 18 Jan 2020 10:57:44 +0000 (11:57 +0100)
committerTim Düsterhus <tim@bastelstu.be>
Sat, 18 Jan 2020 10:57:44 +0000 (11:57 +0100)
files/lib/system/exporter/VB5xExporter.class.php

index c8ad052a1ad7a20cfec1918aabf543c13cf6b3cf..a768d4372e4aff7e4e8b8ad761d10d72c88ba2db 100644 (file)
@@ -835,27 +835,27 @@ class VB5xExporter extends AbstractExporter {
                $message = $attachRegex->replace($message, $attachCallback);
                
                // fix size bbcodes
-               $message = preg_replace_callback('/\[size=\'?(\d+)\'?\]/i', function ($matches) {
-                       $size = 36;
+               $message = preg_replace_callback('/\[size=\'?(\d+)(px)?\'?\]/i', function ($matches) {
+                       $unit = 'scalar';
+                       if (!empty($matches[2])) $unit = $matches[2];
                        
-                       switch ($matches[1]) {
-                               case 1:
-                                       $size = 8;
-                               break;
-                               case 2:
-                                       $size = 10;
-                               break;
-                               case 3:
-                                       $size = 12;
-                               break;
-                               case 4:
-                                       $size = 14;
-                               break;
-                               case 5:
-                                       $size = 18;
+                       $validSizes = [8, 10, 12, 14, 18, 24, 36];
+                       $size = 36;
+                       switch ($unit) {
+                               case 'px':
+                                       foreach ($validSizes as $pt) {
+                                               // 1 Point equals roughly 4/3 Pixels
+                                               if ($pt >= ($matches[1] / 4 * 3)) {
+                                                       $size = $pt;
+                                                       break;
+                                               }
+                                       }
                                break;
-                               case 6:
-                                       $size = 24;
+                               case 'scalar':
+                               default:
+                                       if ($matches[1] >= 1 && $matches[1] <= 6) {
+                                               $size = $validSizes[$matches[1] - 1];
+                                       }
                                break;
                        }