Primeiro, peço desculpas pela falta de imagens. Aparentemente, eu ainda sou muito novo aqui para fazer isso. Vou tentar descrever o problema de forma verbal, e oferecem duas peças-chave do código.
Eu estou com a impressão de uma tv, com linhas de slots de tempo. Quando eu visualizar meu macos tela, parece algo como isto:
40. 8:00 AM 8:30 AM
CNN. Bla Bla Bla Talk Show 1. Whatever Talk Show 1, with
Guests to discuss price Great Host
of bla bla bla. Host will talk about
Whatever
Mas quando eu imprimi-lo, ele trunca alguns, mas não necessariamente todos os dois de texto de linha de itens, como:
40. 8:00 AM 8:30 AM
CNN. Bla Bla Bla Talk Sh ... Whatever Talk Show 1, w...
Guests to discuss pr... Host will talk about
Whatever
Se você perceber a inconsistência, é porque ele não é totalmente consistente. Às vezes eu faço a dois-saída de linha, mas mais frequentemente recebo o truncamento com as reticências. Eu ainda não descobri o padrão subjacente a razão. Mas apenas no quadro da cópia isto é um problema. A tela é de exibir exatamente o que eu quero.
Então, eu tenho caçado em torno de soluções, e de ter tentado muitas variações do Texto() modificadores fixedSize() e lineLimit(). fixedSize tipo de obras, em que os dois itens de linha não truncar, mas, novamente, no modo de exibição de impressão, a linha com a altura da célula de clipes linhas acima e abaixo dele. É realmente agindo como o NSRect enquadrar a imagem de impressão não é grande o suficiente, mas é enorme, e isso não deveria estar acontecendo.
O projeto é demasiado grande para fornecer todo o código, mas espero que seja o suficiente para fornecer a vista em questão, além de que a impressora lógica.
O modo de Exibição (que apresenta corretamente - não truncamento):
struct ScheduleDisplayView: View {
var schedule: [SchedSlot]
let chanmax: CGFloat = 28.0
let fontsize: CGFloat = 7.0
let cellmax: CGFloat = 120
var sortedData : [DayBlock] {
let schedTree: ScheduleTree = ScheduleTree.init()
for ss in schedule {
schedTree.add(schedSlot: ss)
}
return schedTree.dayList
}
var body: some View {
List {
ForEach(sortedData, id: \.dateStamp) { day in
Text("\(day.dateStamp)")
.bold()
ForEach(day.qList, id: \.QTag) { qblock in
ForEach(qblock.chanList.sorted(by: <), id: \.chanTag) { channel in
HStack(alignment: .top, spacing: 0) {
VStack(spacing: 0) {
Text(String(channel.chanTag))
Text(channel.callSign.prefix(4))
}
.border(Color.yellow)
.frame(maxWidth: chanmax, alignment: .topLeading)
.padding(0)
ForEach(channel.timeList, id: \.timeTag) { timecell in
VStack(spacing: 0) {
Text("\(timecell.timeTag)")
.frame(maxWidth: .infinity, alignment: .topLeading)
ForEach(timecell.cellList, id: \.id) { cell in
if cell.startTime != timecell.timeTag {
Text("\(cell.title) (\(cell.startTime))")
.foregroundColor(.blue)
.frame(maxWidth: .infinity, alignment: .topLeading)
.lineLimit(2)
} else {
Text(cell.title)
.foregroundColor(.blue)
.frame(maxWidth: .infinity, alignment: .topLeading)
.lineLimit(2)
}
Text(cell.subtitle)
.frame(maxWidth: .infinity, alignment: .topLeading)
.lineLimit(2)
}
}
}
.border(Color.green)
.frame(maxWidth: .infinity, alignment: .leading)
}
.font(.system(size: fontsize))
.border(Color.blue)
}
}
}
}
}
}
E aqui está a função de impressão. Ele ainda está faltando a funcionalidade de paginação, mas é o que tenho até agora:
func printScheduleView(schedule: [SchedSlot] ) {
let printInfo = NSPrintInfo.shared
printInfo.topMargin = 0.0
printInfo.bottomMargin = 0.0
printInfo.rightMargin = 0.0
printInfo.leftMargin = 0.0
printInfo.horizontalPagination = .fit
printInfo.verticalPagination = .automatic
printInfo.isHorizontallyCentered = false
printInfo.isVerticallyCentered = false
let view = ScheduleDisplayView(schedule: schedule)
let contentRect = NSRect(x: 0, y: 0, width: 900, height: 2800)
let viewToPrint = NSHostingView(rootView: view)
viewToPrint.frame = contentRect
let bitMap = viewToPrint.bitmapImageRepForCachingDisplay(in: contentRect)!
viewToPrint.cacheDisplay(in: contentRect, to: bitMap)
let image = NSImage(size: bitMap.size)
image.addRepresentation(bitMap)
let imageView = NSImageView(frame: contentRect)
imageView.image = image
let printOperation = NSPrintOperation(view: imageView, printInfo: printInfo)
printOperation.showsPrintPanel = true
printOperation.showsProgressPanel = true
printOperation.run()
}