mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-02 22:17:06 +08:00
Add inline member on the DrawContext structure
This commit is contained in:
parent
ba5b493b70
commit
7004fb0d0e
@ -107,13 +107,16 @@ func (div *Division) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
|
||||
ctx.Height -= div.margins.top
|
||||
}
|
||||
|
||||
// Set the inline mode of the division to the context
|
||||
ctx.Inline = div.inline
|
||||
|
||||
// Draw.
|
||||
divCtx := ctx
|
||||
tmpCtx := ctx
|
||||
var lineHeight float64
|
||||
|
||||
// Draw.
|
||||
for _, component := range div.components {
|
||||
if div.inline {
|
||||
if ctx.Inline {
|
||||
if (ctx.X-divCtx.X)+component.Width() <= ctx.Width {
|
||||
ctx.Y = tmpCtx.Y
|
||||
ctx.Height = tmpCtx.Height
|
||||
@ -147,9 +150,7 @@ func (div *Division) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
|
||||
}
|
||||
|
||||
// Apply padding/margins.
|
||||
if !div.inline {
|
||||
updCtx.X = ctx.X
|
||||
} else {
|
||||
if ctx.Inline {
|
||||
if dl := ctx.Height - updCtx.Height; dl > lineHeight {
|
||||
lineHeight = dl
|
||||
}
|
||||
@ -159,11 +160,16 @@ func (div *Division) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
|
||||
tmpCtx.Height = divCtx.Height
|
||||
lineHeight = 0
|
||||
}
|
||||
} else {
|
||||
updCtx.X = ctx.X
|
||||
}
|
||||
|
||||
ctx = updCtx
|
||||
}
|
||||
|
||||
// Restore the original inline mode of the context
|
||||
ctx.Inline = origCtx.Inline
|
||||
|
||||
if div.positioning.isRelative() {
|
||||
// Move back X to same start of line.
|
||||
ctx.X = origCtx.X
|
||||
|
@ -43,4 +43,7 @@ type DrawContext struct {
|
||||
// Absolute Page size, widths and height.
|
||||
PageWidth float64
|
||||
PageHeight float64
|
||||
|
||||
// Controls whether the components are stacked horizontally
|
||||
Inline bool
|
||||
}
|
||||
|
@ -516,10 +516,12 @@ func drawParagraphOnBlock(blk *Block, p *Paragraph, ctx DrawContext) (DrawContex
|
||||
|
||||
if p.positioning.isRelative() {
|
||||
pHeight := p.Height() + p.margins.bottom
|
||||
|
||||
ctx.X += p.Width() + p.margins.right
|
||||
ctx.Y += pHeight
|
||||
ctx.Height -= pHeight
|
||||
|
||||
if ctx.Inline {
|
||||
ctx.X += p.Width() + p.margins.right
|
||||
}
|
||||
}
|
||||
|
||||
return ctx, nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user