From e9b3fa707d77ca68efd8bd84ab15c0bf5c689839 Mon Sep 17 00:00:00 2001 From: Vinicius Cunha Date: Fri, 10 Jul 2026 10:26:23 -0300 Subject: [PATCH 1/2] =?UTF-8?q?fix(NFCe):=20altera=20c=C3=A1lculo=20do=20t?= =?UTF-8?q?amanho=20da=20p=C3=A1gina=20=C3=BAnica=20para=20utilizar=20Unli?= =?UTF-8?q?mitedHeight=20inv=C3=A9s=20de=20calcular=20o=20tamanho=20de=20c?= =?UTF-8?q?ada=20componente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NFe.Danfe.Base/NFCe/NFCe.frx | 436 ++++++++++++++++++++++------------- 1 file changed, 279 insertions(+), 157 deletions(-) diff --git a/NFe.Danfe.Base/NFCe/NFCe.frx b/NFe.Danfe.Base/NFCe/NFCe.frx index ecaadeb0a..dbb4ce50b 100644 --- a/NFe.Danfe.Base/NFCe/NFCe.frx +++ b/NFe.Danfe.Base/NFCe/NFCe.frx @@ -1,5 +1,5 @@  - + using System; using System.Collections; using System.Collections.Generic; @@ -187,132 +187,28 @@ namespace FastReport { phbCancelado.Visible = ((Boolean)Report.GetParameterValue("NfceCancelado")); - if (!Engine.FinalPass) - return; if ( (NfceModoImpressao) ((Int32)Report.GetParameterValue("NfceModoImpressao")) != NfceModoImpressao.UnicaPagina) return; - PgNfce.PaperHeight = - (rtbEmitLogoHeight + - phbEmitenteHeight + - ((Boolean)Report.GetParameterValue("NfceCancelado") ? phbCancelado.Height : 0)+ - ghbProdutosUmaLinhaHeight + - dbProdutosUmaLinhaHeight + - ghbProdutosDuasLinhasHeight + - dbProdutosDuasLinhasHeight + - gfbProdutosHeight + - dbPagamentoHeight + - dbDetPagamentoHeight + - dbTributosHeight + - dbObservacaoHeight + - dbInfoFiscalHeight + - dbNumeroSerieDhHeight + - dbConsultaHeight + - dbDestinatarioHeight + - dbQrCodeNormalHeight + - dbQrCodeLateralHeight + - dbProtocoloHeigth - ) / - Units.Millimeters + PgNfce.TopMargin + PgNfce.BottomMargin; - - } - - float dbProdutosUmaLinhaHeight; - private void dbProdutosUmaLinha_AfterPrint(object sender, EventArgs e) - { - dbProdutosUmaLinhaHeight += (dbProdutosUmaLinha.Visible ? dbProdutosUmaLinha.Height : 0) + (cbDescontoItemUmaLinha.Visible ? cbDescontoItemUmaLinha.Height : 0); - } - - float dbProdutosDuasLinhasHeight; - private void dbProdutosDuasLinhas_AfterPrint(object sender, EventArgs e) - { - dbProdutosDuasLinhasHeight += (dbProdutosDuasLinhas.Visible ?dbProdutosDuasLinhas.Height : 0) + (cbDescontoItemDuasLinhas.Visible ? cbDescontoItemDuasLinhas.Height : 0); - } - - float dbInfoFiscalHeight; - private void dbInfoFiscal_AfterPrint(object sender, EventArgs e) - { - dbInfoFiscalHeight = (dbInfoFiscal.Visible ? dbInfoFiscal.Height : 0); - } - - float dbNumeroSerieDhHeight; - private void dbNumeroSerieDh_AfterPrint(object sender, EventArgs e) - { - dbNumeroSerieDhHeight = (dbNumeroSerieDh.Visible ? dbNumeroSerieDh.Height : 0); - } - - float dbConsultaHeight; - private void dbConsulta_AfterPrint(object sender, EventArgs e) - { - dbConsultaHeight = (dbConsulta.Visible ? dbConsulta.Height : 0); - } - - float rtbEmitLogoHeight; - private void rtbEmitLogo_AfterPrint(object sender, EventArgs e) - { - rtbEmitLogoHeight = (rtbEmitLogo.Visible ? rtbEmitLogo.Height : 0); - } - - float phbEmitenteHeight; - private void phbEmitente_AfterPrint(object sender, EventArgs e) - { - phbEmitenteHeight = (phbEmitente.Visible ? phbEmitente.Height : 0); - } - - float ghbProdutosUmaLinhaHeight; - private void ghbProdutosUmaLinha_AfterPrint(object sender, EventArgs e) - { - ghbProdutosUmaLinhaHeight = (ghbProdutosUmaLinha.Visible ? ghbProdutosUmaLinha.Height : 0); - } - - float ghbProdutosDuasLinhasHeight; - private void ghbProdutosDuasLinhas_AfterPrint(object sender, EventArgs e) - { - ghbProdutosDuasLinhasHeight = (ghbProdutosDuasLinhas.Visible ? ghbProdutosDuasLinhas.Height : 0); - } - - float gfbProdutosHeight; - private void gfbProdutos_AfterPrint(object sender, EventArgs e) - { - gfbProdutosHeight = (gfbProdutos.Visible ? gfbProdutos.Height : 0); - } - - float dbPagamentoHeight; - private void dbPagamento_AfterPrint(object sender, EventArgs e) - { - dbPagamentoHeight = (dbPagamento.Visible ? dbPagamento.Height : 0); - } - - float dbDetPagamentoHeight; - private void dbDetPagamento_AfterPrint(object sender, EventArgs e) - { - dbDetPagamentoHeight = (dbDetPagamento.Visible ? dbDetPagamento.Height : 0); - } - - float dbTributosHeight; - private void dbTributos_AfterPrint(object sender, EventArgs e) - { - dbTributosHeight = (dbTributos.Visible ? dbTributos.Height : 0); - } - - float dbObservacaoHeight; - private void dbObservacao_AfterPrint(object sender, EventArgs e) - { - dbObservacaoHeight = (dbObservacao.Visible ? dbObservacao.Height : 0); - } - - float dbDestinatarioHeight; - private void dbDestinatario_AfterPrint(object sender, EventArgs e) - { - dbDestinatarioHeight = (dbDestinatario.Visible ? dbDestinatario.Height : 0); - } - - float dbQrCodeNormalHeight; - private void dbQrCode_AfterPrint(object sender, EventArgs e) - { - dbQrCodeNormalHeight = (dbQrCodeNormal.Visible ? dbQrCodeNormal.Height : 0); + PgNfce.UnlimitedHeight = true; } + + + + + + + + + + + + + + + + private void cbDesconto_BeforePrint(object sender, EventArgs e) { cbDesconto.Visible = ((Decimal)Report.GetColumnValue("NFCe.NFe.infNFe.total.ICMSTot.vDesc")) > 0; @@ -339,25 +235,14 @@ namespace FastReport dbTroco.Visible = Report.GetColumnValue("NFCe.NFe.infNFe.pag.vTroco") != null; } - private void dbQrCodeLateral_BeforePrint(object sender, EventArgs e) { TrataCamposDestinatario(); dbQrCodeLateral.Visible = ((NfceLayoutQrCode) Report.GetParameterValue("NfceLayoutQrCode") == NfceLayoutQrCode.Lateral); } - float dbQrCodeLateralHeight; - private void dbQrCodeLateral_AfterPrint(object sender, EventArgs e) - { - dbQrCodeLateralHeight = (dbQrCodeLateral.Visible ? dbQrCodeLateral.Height : 0); - } - - float dbProtocoloHeigth; - private void dbProtocolo_AfterPrint(object sender, EventArgs e) - { - dbProtocoloHeigth = (dbProtocolo.Visible ? dbProtocolo.Height : 0); - } - + + private void dbQrCodeNormal_BeforePrint(object sender, EventArgs e) { dbQrCodeNormal.Visible = ((NfceLayoutQrCode) Report.GetParameterValue("NfceLayoutQrCode") == NfceLayoutQrCode.Abaixo); @@ -437,7 +322,22 @@ namespace FastReport + + + + + + + + + + + + + + + @@ -572,7 +472,9 @@ namespace FastReport - + + + @@ -584,9 +486,13 @@ namespace FastReport + + + + @@ -594,9 +500,14 @@ namespace FastReport - - - + + + + + + + + @@ -676,7 +587,154 @@ namespace FastReport + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -694,6 +752,11 @@ namespace FastReport + + + + + @@ -754,7 +817,48 @@ namespace FastReport + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -851,9 +955,27 @@ namespace FastReport + + + + + + + + + + + + + + + + + + @@ -938,10 +1060,10 @@ namespace FastReport - + - + @@ -954,7 +1076,7 @@ namespace FastReport - + @@ -963,7 +1085,7 @@ namespace FastReport - + @@ -984,7 +1106,7 @@ namespace FastReport - + @@ -993,7 +1115,7 @@ namespace FastReport - + @@ -1013,7 +1135,7 @@ namespace FastReport - + @@ -1038,11 +1160,11 @@ namespace FastReport - + - + @@ -1051,16 +1173,16 @@ namespace FastReport - + - + - + - + @@ -1070,16 +1192,16 @@ namespace FastReport - + - + - + @@ -1087,10 +1209,10 @@ namespace FastReport - + - + From 7d89baa2132aac6c880293bda0b6358c4f0aa6b1 Mon Sep 17 00:00:00 2001 From: Vinicius Cunha Date: Wed, 15 Jul 2026 14:12:21 -0300 Subject: [PATCH 2/2] retornada a soma das bandas, incluindo as que faltavam e compactado o top do design --- NFe.Danfe.Base/NFCe/NFCe.frx | 256 +++++++++++++++++++++++++++++------ 1 file changed, 214 insertions(+), 42 deletions(-) diff --git a/NFe.Danfe.Base/NFCe/NFCe.frx b/NFe.Danfe.Base/NFCe/NFCe.frx index dbb4ce50b..af072cdf6 100644 --- a/NFe.Danfe.Base/NFCe/NFCe.frx +++ b/NFe.Danfe.Base/NFCe/NFCe.frx @@ -187,28 +187,202 @@ namespace FastReport { phbCancelado.Visible = ((Boolean)Report.GetParameterValue("NfceCancelado")); + if (!Engine.FinalPass) + return; if ( (NfceModoImpressao) ((Int32)Report.GetParameterValue("NfceModoImpressao")) != NfceModoImpressao.UnicaPagina) return; - PgNfce.UnlimitedHeight = true; - } + CompactarTopDeDesignDasBandas(); + PgNfce.PaperHeight = (rtbEmitLogoHeight + + phbEmitenteHeight + + ((Boolean)Report.GetParameterValue("NfceCancelado") ? phbCancelado.Height : 0)+ + ghbProdutosUmaLinhaHeight + + dbProdutosUmaLinhaHeight + + ghbProdutosDuasLinhasHeight + + dbProdutosDuasLinhasHeight + + gfbProdutosHeight + + cbDescontoHeight + + child2Height + + dbPagamentoHeight + + dbDetPagamentoHeight + + dbTrocoHeight + + dbTributosHeight + + dbObservacaoHeight + + dbInfoFiscalHeight + + dbNumeroSerieDhHeight + + dbConsultaHeight + + dbInfProtxMsgHeight + + dbDestinatarioHeight + + dbQrCodeNormalHeight + + dbQrCodeLateralHeight + + dbProtocoloHeigth + + dbTextoRodapeHeight + ) / Units.Millimeters + PgNfce.TopMargin + PgNfce.BottomMargin; + } - - - - - - - - - - - - - - - + /// <summary> + /// Compacta o Top de DESIGN de todas as bandas da página para ~0, preservando a ordem relativa + /// (incrementos de 0.01px). No modo de impressão em página única o PaperHeight é calculado do + /// tamanho do conteúdo e pode ficar menor que o Top de design das últimas bandas (~297mm de + /// layout empilhado no designer); nesse caso, ao calcular a altura de bandas CanShrink, o + /// FastReport aplica altura = min(alturaDoConteudo, alturaDaPagina - TopDeDesign) e o resultado + /// fica NEGATIVO, puxando as bandas seguintes para cima e desmontando o fim do cupom (QR Code, + /// protocolo, tributos e rodapé) em cupons com poucos itens. O Top de design não define a + /// posição real de impressão (as bandas fluem em sequência), então compactá-lo não altera o + /// visual e apenas elimina o recorte. + /// </summary> + private void CompactarTopDeDesignDasBandas() + { + float topCompacto = 0; + foreach (Base c in PgNfce.AllObjects) + { + BandBase b = c as BandBase; + if (b == null) + continue; + b.Top = topCompacto; + topCompacto += 0.01f; + } + } + + float dbProdutosUmaLinhaHeight; + private void dbProdutosUmaLinha_AfterPrint(object sender, EventArgs e) + { + dbProdutosUmaLinhaHeight += (dbProdutosUmaLinha.Visible ? dbProdutosUmaLinha.Height : 0) + (cbDescontoItemUmaLinha.Visible ? cbDescontoItemUmaLinha.Height : 0); + } + + float dbProdutosDuasLinhasHeight; + private void dbProdutosDuasLinhas_AfterPrint(object sender, EventArgs e) + { + dbProdutosDuasLinhasHeight += (dbProdutosDuasLinhas.Visible ?dbProdutosDuasLinhas.Height : 0) + (cbDescontoItemDuasLinhas.Visible ? cbDescontoItemDuasLinhas.Height : 0); + } + + float dbInfoFiscalHeight; + private void dbInfoFiscal_AfterPrint(object sender, EventArgs e) + { + dbInfoFiscalHeight = (dbInfoFiscal.Visible ? dbInfoFiscal.Height : 0); + } + + float dbNumeroSerieDhHeight; + private void dbNumeroSerieDh_AfterPrint(object sender, EventArgs e) + { + dbNumeroSerieDhHeight = (dbNumeroSerieDh.Visible ? dbNumeroSerieDh.Height : 0); + } + + float dbConsultaHeight; + private void dbConsulta_AfterPrint(object sender, EventArgs e) + { + dbConsultaHeight = (dbConsulta.Visible ? dbConsulta.Height : 0); + } + + float rtbEmitLogoHeight; + private void rtbEmitLogo_AfterPrint(object sender, EventArgs e) + { + rtbEmitLogoHeight = (rtbEmitLogo.Visible ? rtbEmitLogo.Height : 0); + } + + float phbEmitenteHeight; + private void phbEmitente_AfterPrint(object sender, EventArgs e) + { + phbEmitenteHeight = (phbEmitente.Visible ? phbEmitente.Height : 0); + } + + float ghbProdutosUmaLinhaHeight; + private void ghbProdutosUmaLinha_AfterPrint(object sender, EventArgs e) + { + ghbProdutosUmaLinhaHeight = (ghbProdutosUmaLinha.Visible ? ghbProdutosUmaLinha.Height : 0); + } + + float ghbProdutosDuasLinhasHeight; + private void ghbProdutosDuasLinhas_AfterPrint(object sender, EventArgs e) + { + ghbProdutosDuasLinhasHeight = (ghbProdutosDuasLinhas.Visible ? ghbProdutosDuasLinhas.Height : 0); + } + + float gfbProdutosHeight; + private void gfbProdutos_AfterPrint(object sender, EventArgs e) + { + gfbProdutosHeight = (gfbProdutos.Visible ? gfbProdutos.Height : 0); + } + + float dbPagamentoHeight; + private void dbPagamento_AfterPrint(object sender, EventArgs e) + { + dbPagamentoHeight += (dbPagamento.Visible ? dbPagamento.Height : 0); + } + + float dbDetPagamentoHeight; + private void dbDetPagamento_AfterPrint(object sender, EventArgs e) + { + dbDetPagamentoHeight += (dbDetPagamento.Visible ? dbDetPagamento.Height : 0); + } + + float dbTributosHeight; + private void dbTributos_AfterPrint(object sender, EventArgs e) + { + dbTributosHeight = (dbTributos.Visible ? dbTributos.Height : 0); + } + + float dbObservacaoHeight; + private void dbObservacao_AfterPrint(object sender, EventArgs e) + { + dbObservacaoHeight = (dbObservacao.Visible ? dbObservacao.Height : 0); + } + + float dbDestinatarioHeight; + private void dbDestinatario_AfterPrint(object sender, EventArgs e) + { + dbDestinatarioHeight = (dbDestinatario.Visible ? dbDestinatario.Height : 0); + } + + float dbQrCodeNormalHeight; + private void dbQrCode_AfterPrint(object sender, EventArgs e) + { + dbQrCodeNormalHeight = (dbQrCodeNormal.Visible ? dbQrCodeNormal.Height : 0); + } + + float dbQrCodeLateralHeight; + private void dbQrCodeLateral_AfterPrint(object sender, EventArgs e) + { + dbQrCodeLateralHeight = (dbQrCodeLateral.Visible ? dbQrCodeLateral.Height : 0); + } + + float dbProtocoloHeigth; + private void dbProtocolo_AfterPrint(object sender, EventArgs e) + { + dbProtocoloHeigth = (dbProtocolo.Visible ? dbProtocolo.Height : 0); + } + + float dbTrocoHeight; + private void dbTroco_AfterPrint(object sender, EventArgs e) + { + dbTrocoHeight = (dbTroco.Visible ? dbTroco.Height : 0); + } + + float cbDescontoHeight; + private void cbDesconto_AfterPrint(object sender, EventArgs e) + { + cbDescontoHeight = (cbDesconto.Visible ? cbDesconto.Height : 0); + } + + float child2Height; + private void Child2_AfterPrint(object sender, EventArgs e) + { + child2Height = (Child2.Visible ? Child2.Height : 0); + } + + float dbInfProtxMsgHeight; + private void dbInfProtxMsg_AfterPrint(object sender, EventArgs e) + { + dbInfProtxMsgHeight = (dbInfProtxMsg.Visible ? dbInfProtxMsg.Height : 0); + } + + float dbTextoRodapeHeight; + private void dbTextoRodape_AfterPrint(object sender, EventArgs e) + { + dbTextoRodapeHeight = (dbTextoRodape.Visible ? dbTextoRodape.Height : 0); + } + private void cbDesconto_BeforePrint(object sender, EventArgs e) { cbDesconto.Visible = ((Decimal)Report.GetColumnValue("NFCe.NFe.infNFe.total.ICMSTot.vDesc")) > 0; @@ -241,8 +415,6 @@ namespace FastReport dbQrCodeLateral.Visible = ((NfceLayoutQrCode) Report.GetParameterValue("NfceLayoutQrCode") == NfceLayoutQrCode.Lateral); } - - private void dbQrCodeNormal_BeforePrint(object sender, EventArgs e) { dbQrCodeNormal.Visible = ((NfceLayoutQrCode) Report.GetParameterValue("NfceLayoutQrCode") == NfceLayoutQrCode.Abaixo); @@ -1060,10 +1232,10 @@ namespace FastReport - + - + @@ -1076,7 +1248,7 @@ namespace FastReport - + @@ -1085,7 +1257,7 @@ namespace FastReport - + @@ -1106,7 +1278,7 @@ namespace FastReport - + @@ -1115,7 +1287,7 @@ namespace FastReport - + @@ -1135,7 +1307,7 @@ namespace FastReport - + @@ -1148,60 +1320,60 @@ namespace FastReport - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1209,13 +1381,13 @@ namespace FastReport - + - + - +