Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/PhpSpreadsheet/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,16 @@ public function getSuperscript()
*/
public function setSuperscript($pValue)
{
if ($pValue == '') {
$pValue = false;
}
$pValu2 = !$pValue;
$pValue = !$pValu2;
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['superscript' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->superscript = $pValue;
$this->subscript = !$pValue;
if ($this->superscript) {
$this->subscript = false;
}
}

return $this;
Expand Down Expand Up @@ -400,15 +401,16 @@ public function getSubscript()
*/
public function setSubscript($pValue)
{
if ($pValue == '') {
$pValue = false;
}
$pValu2 = !$pValue;
$pValue = !$pValu2;
if ($this->isSupervisor) {
$styleArray = $this->getStyleArray(['subscript' => $pValue]);
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->subscript = $pValue;
$this->superscript = !$pValue;
if ($this->subscript) {
$this->superscript = false;
}
}

return $this;
Expand Down
42 changes: 42 additions & 0 deletions tests/PhpSpreadsheetTests/Style/FontTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Style;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;

class FontTest extends TestCase
{
public function testSuperSubScript(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$cell = $sheet->getCell('A1');
$cell->setValue('Cell A1');
$font = $cell->getStyle()->getFont();
$font->setSuperscript(true);
$font->setSubscript(true);
self::assertFalse($font->getSuperscript(), 'Earlier set true loses');
self::assertTrue($font->getSubscript(), 'Last set true wins');
$font->setSubscript(true);
$font->setSuperscript(true);
self::assertTrue($font->getSuperscript(), 'Last set true wins');
self::assertFalse($font->getSubscript(), 'Earlier set true loses');
$font->setSuperscript(false);
$font->setSubscript(false);
self::assertFalse($font->getSuperscript(), 'False remains unchanged');
self::assertFalse($font->getSubscript(), 'False remains unchanged');
$font->setSubscript(false);
$font->setSuperscript(false);
self::assertFalse($font->getSuperscript(), 'False remains unchanged');
self::assertFalse($font->getSubscript(), 'False remains unchanged');
$font->setSubscript(true);
$font->setSuperscript(false);
self::assertFalse($font->getSuperscript(), 'False remains unchanged');
self::assertTrue($font->getSubscript(), 'True remains unchanged');
$font->setSubscript(false);
$font->setSuperscript(true);
self::assertTrue($font->getSuperscript());
self::assertFalse($font->getSubscript(), 'False remains unchanged');
}
}