forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We used existence to indicate non-boldness, but the element can exist with a false value which also means bold is disabled. Fixes unidoc#204
- Loading branch information
Showing
3 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2018 Baliance. All rights reserved. | ||
// | ||
// Use of this source code is governed by the terms of the Affero GNU General | ||
// Public License version 3.0 as published by the Free Software Foundation and | ||
// appearing in the file LICENSE included in the packaging of this file. A | ||
// commercial license can be purchased by contacting [email protected]. | ||
|
||
package document | ||
|
||
import "baliance.com/gooxml/schema/soo/wml" | ||
|
||
// OnOffValue represents an on/off value that can also be unset | ||
type OnOffValue byte | ||
|
||
// OnOffValue constants | ||
const ( | ||
OnOffValueUnset OnOffValue = iota | ||
OnOffValueOff | ||
OnOffValueOn | ||
) | ||
|
||
func convertOnOff(v *wml.CT_OnOff) OnOffValue { | ||
if v == nil { | ||
return OnOffValueUnset | ||
} | ||
// set, but the value is set to false | ||
if v.ValAttr != nil && v.ValAttr.Bool != nil && *v.ValAttr.Bool == false { | ||
return OnOffValueOff | ||
} | ||
// element exists, which implies turned on (and boolean value can't be false) | ||
return OnOffValueOn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,18 @@ | |
// appearing in the file LICENSE included in the packaging of this file. A | ||
// commercial license can be purchased by contacting [email protected]. | ||
|
||
package document_test | ||
package document | ||
|
||
import ( | ||
"testing" | ||
|
||
"baliance.com/gooxml/document" | ||
"baliance.com/gooxml" | ||
"baliance.com/gooxml/schema/soo/ofc/sharedTypes" | ||
"baliance.com/gooxml/schema/soo/wml" | ||
) | ||
|
||
func TestRunClear(t *testing.T) { | ||
doc := document.New() | ||
doc := New() | ||
para := doc.AddParagraph() | ||
run := para.AddRun() | ||
if len(run.X().EG_RunInnerContent) != 0 { | ||
|
@@ -35,3 +37,28 @@ func TestRunClear(t *testing.T) { | |
t.Errorf("expected inner content of length zero, had %d", len(run.X().EG_RunInnerContent)) | ||
} | ||
} | ||
|
||
// Issue #204 | ||
func TestRunPropertiesBold(t *testing.T) { | ||
r := RunProperties{wml.NewCT_RPr()} | ||
if r.IsBold() { | ||
t.Errorf("expected IsBold = false with no bold element") | ||
} | ||
r.x.B = wml.NewCT_OnOff() | ||
r.x.B.ValAttr = &sharedTypes.ST_OnOff{} | ||
r.x.B.ValAttr.Bool = gooxml.Bool(false) | ||
|
||
if r.IsBold() { | ||
t.Errorf("expected IsBold = false with false bool value") | ||
} | ||
|
||
r.x.B.ValAttr.Bool = gooxml.Bool(true) | ||
if !r.IsBold() { | ||
t.Errorf("expected IsBold = true with true bool value") | ||
} | ||
|
||
r.x.B = wml.NewCT_OnOff() | ||
if !r.IsBold() { | ||
t.Errorf("expected IsBold = true with existence and no bool value") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters