Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new exported function GetCellPixelsWithCoordinates #1842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
14 changes: 11 additions & 3 deletions picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,10 @@ func (f *File) drawingsWriter() {
})
}

// drawingResize calculate the height and width after resizing.
func (f *File) drawingResize(sheet, cell string, width, height float64, opts *GraphicOptions) (w, h, c, r int, err error) {
// GetCellPixelsWithCoordinates returns the pixel dimensions of a specified cell within a given sheet,
// accounting for merged cells. This function calculates the total pixel width and height
// for individual or merged cells and provides the column and row index of the cell.
func (f *File) GetCellPixelsWithCoordinates(sheet, cell string) (cellWidth, cellHeight, c, r int, err error) {
var mergeCells []MergeCell
mergeCells, err = f.GetMergeCells(sheet)
if err != nil {
Expand All @@ -687,7 +689,7 @@ func (f *File) drawingResize(sheet, cell string, width, height float64, opts *Gr
if c, r, err = CellNameToCoordinates(cell); err != nil {
return
}
cellWidth, cellHeight := f.getColWidth(sheet, c), f.getRowHeight(sheet, r)
cellWidth, cellHeight = f.getColWidth(sheet, c), f.getRowHeight(sheet, r)
for _, mergeCell := range mergeCells {
if inMergeCell {
continue
Expand All @@ -707,6 +709,12 @@ func (f *File) drawingResize(sheet, cell string, width, height float64, opts *Gr
cellHeight += f.getRowHeight(sheet, row)
}
}
return
}

// drawingResize calculate the height and width after resizing.
func (f *File) drawingResize(sheet, cell string, width, height float64, opts *GraphicOptions) (w, h, c, r int, err error) {
cellWidth, cellHeight, c, r, err := f.GetCellPixelsWithCoordinates(sheet, cell)
if float64(cellWidth) < width {
asp := float64(cellWidth) / width
width, height = float64(cellWidth), height*asp
Expand Down