This closes #279, refs #1536, change the default point to pixels conversion factor

This commit is contained in:
xuri 2023-05-19 19:53:18 +08:00
parent 08ba2723fe
commit a246db6a40
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
3 changed files with 8 additions and 7 deletions

View File

@ -94,7 +94,7 @@ func TestChartSize(t *testing.T) {
} }
if !assert.Equal(t, 14, anchor.To.Col, "Expected 'to' column 14") || if !assert.Equal(t, 14, anchor.To.Col, "Expected 'to' column 14") ||
!assert.Equal(t, 27, anchor.To.Row, "Expected 'to' row 27") { !assert.Equal(t, 29, anchor.To.Row, "Expected 'to' row 29") {
t.FailNow() t.FailNow()
} }

11
rows.go
View File

@ -380,6 +380,9 @@ func (f *File) getRowHeight(sheet string, row int) int {
return int(convertRowHeightToPixels(*v.Ht)) return int(convertRowHeightToPixels(*v.Ht))
} }
} }
if ws.SheetFormatPr != nil && ws.SheetFormatPr.DefaultRowHeight > 0 {
return int(convertRowHeightToPixels(ws.SheetFormatPr.DefaultRowHeight))
}
// Optimization for when the row heights haven't changed. // Optimization for when the row heights haven't changed.
return int(defaultRowHeightPixels) return int(defaultRowHeightPixels)
} }
@ -390,7 +393,7 @@ func (f *File) getRowHeight(sheet string, row int) int {
// height, err := f.GetRowHeight("Sheet1", 1) // height, err := f.GetRowHeight("Sheet1", 1)
func (f *File) GetRowHeight(sheet string, row int) (float64, error) { func (f *File) GetRowHeight(sheet string, row int) (float64, error) {
if row < 1 { if row < 1 {
return defaultRowHeightPixels, newInvalidRowNumberError(row) return defaultRowHeight, newInvalidRowNumberError(row)
} }
ht := defaultRowHeight ht := defaultRowHeight
ws, err := f.workSheetReader(sheet) ws, err := f.workSheetReader(sheet)
@ -840,10 +843,8 @@ func (f *File) SetRowStyle(sheet string, start, end, styleID int) error {
// cell from user's units to pixels. If the height hasn't been set by the user // cell from user's units to pixels. If the height hasn't been set by the user
// we use the default value. If the row is hidden it has a value of zero. // we use the default value. If the row is hidden it has a value of zero.
func convertRowHeightToPixels(height float64) float64 { func convertRowHeightToPixels(height float64) float64 {
var pixels float64
if height == 0 { if height == 0 {
return pixels return 0
} }
pixels = math.Ceil(4.0 / 3.0 * height) return math.Ceil(4.0 / 3.4 * height)
return pixels
} }

View File

@ -144,7 +144,7 @@ const (
pivotTableVersion = 3 pivotTableVersion = 3
defaultPictureScale = 1.0 defaultPictureScale = 1.0
defaultChartDimensionWidth = 480 defaultChartDimensionWidth = 480
defaultChartDimensionHeight = 290 defaultChartDimensionHeight = 260
defaultChartLegendPosition = "bottom" defaultChartLegendPosition = "bottom"
defaultChartShowBlanksAs = "gap" defaultChartShowBlanksAs = "gap"
defaultShapeSize = 160 defaultShapeSize = 160