Skip to content

Commit

Permalink
fix: 修复插入图片时,尺寸计算不准确的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
clearmann committed Nov 5, 2024
1 parent 5d2a928 commit ed3fe5c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions document/anchoreddrawing.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func (a AnchoredDrawing) SetVAlignment(v wml.WdST_AlignV) {

// SetSize sets the size of the displayed image on the page.
func (a AnchoredDrawing) SetSize(w, h measurement.Distance) {
a.x.Extent.CxAttr = int64(float64(w*measurement.Pixel72) / measurement.EMU)
a.x.Extent.CyAttr = int64(float64(h*measurement.Pixel72) / measurement.EMU)
a.x.Extent.CxAttr = int64(float64(w*measurement.NOFFZZ) / measurement.Dpi)
a.x.Extent.CyAttr = int64(float64(h*measurement.NOFFZZ) / measurement.Dpi)
}

// SetTextWrapNone unsets text wrapping so the image can float on top of the
Expand Down
6 changes: 4 additions & 2 deletions document/inlinedrawing.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (i InlineDrawing) GetImage() (common.ImageRef, bool) {
}

// SetSize sets the size of the displayed image on the page.
// When setting the image size, please set the size in pixels,
// the program will automatically calculate the unit to meet the ooxml regulations.
func (i InlineDrawing) SetSize(w, h measurement.Distance) {
i.x.Extent.CxAttr = int64(float64(w*measurement.Pixel72) / measurement.EMU)
i.x.Extent.CyAttr = int64(float64(h*measurement.Pixel72) / measurement.EMU)
i.x.Extent.CxAttr = int64(float64(w*measurement.NOFFZZ) / measurement.Dpi)
i.x.Extent.CyAttr = int64(float64(h*measurement.NOFFZZ) / measurement.Dpi)
}
4 changes: 3 additions & 1 deletion measurement/distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ type Distance float64
const (
Zero Distance = 0
Point = 1
NOFFZZ = 914400.0
Pixel72 = 1.0 / 72.0 * Inch
Pixel96 = 1.0 / 96.0 * Inch
HalfPoint = 1.0 / 2.0 * Point
Character = 7 * Point
Millimeter = 2.83465 * Point
Centimeter = 10 * Millimeter
Inch = 72 * Point
Dpi = 96 * Point
Foot = 12 * Inch
Twips = 1.0 / 20.0 * Point
EMU = 1.0 / 914400.0 * Inch
EMU = 1.0 / NOFFZZ * Inch
HundredthPoint = 1 / 100.0
Dxa = Twips
)

0 comments on commit ed3fe5c

Please sign in to comment.