Skip to content

Commit cd21f00

Browse files
committed
2 parents cfea283 + 9efce21 commit cd21f00

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/card.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function utf8Strlen(string $string): int
221221
function splitLines(string $text, int $maxChars, int $line1Offset): string
222222
{
223223
// if too many characters, insert \n before a " " or "-" if possible
224-
if (utf8Strlen($text) > $maxChars && strpos($text, "\n") === false) {
224+
if ($maxChars > 0 && utf8Strlen($text) > $maxChars && strpos($text, "\n") === false) {
225225
// prefer splitting at " - " if possible
226226
if (strpos($text, " - ") !== false) {
227227
$text = str_replace(" - ", "\n- ", $text);
@@ -393,7 +393,7 @@ function generateCard(array $stats, array $params = null): string
393393
}
394394

395395
// if the translations contain over max characters or a newline, split the text into two tspan elements
396-
$maxCharsPerLineLabels = intval(floor($cardWidth / $numColumns / 7.5));
396+
$maxCharsPerLineLabels = $numColumns > 0 ? intval(floor($cardWidth / $numColumns / 7.5)) : 0;
397397
$totalContributionsText = splitLines($localeTranslations["Total Contributions"], $maxCharsPerLineLabels, -9);
398398
if ($stats["mode"] === "weekly") {
399399
$currentStreakText = splitLines($localeTranslations["Week Streak"], $maxCharsPerLineLabels, -9);
@@ -404,7 +404,7 @@ function generateCard(array $stats, array $params = null): string
404404
}
405405

406406
// if the ranges contain over max characters, split the text into two tspan elements
407-
$maxCharsPerLineDates = intval(floor($cardWidth / $numColumns / 6));
407+
$maxCharsPerLineDates = $numColumns > 0 ? intval(floor($cardWidth / $numColumns / 6)) : 0;
408408
$totalContributionsRange = splitLines($totalContributionsRange, $maxCharsPerLineDates, 0);
409409
$currentStreakRange = splitLines($currentStreakRange, $maxCharsPerLineDates, 0);
410410
$longestStreakRange = splitLines($longestStreakRange, $maxCharsPerLineDates, 0);

0 commit comments

Comments
 (0)