सबसे पहले, मैं माफी माँगता हूँ की कमी के लिए छवियों. जाहिरा तौर पर मैं अभी भी यहाँ नया करने के लिए करते हैं कि. मैं करने का प्रयास करेंगे समस्या का वर्णन है, मौखिक रूप से प्रदान करते हैं और दो कुंजी कोड के टुकड़े.
मैं मुद्रण कर रहा हूँ एक टीवी अनुसूची, की पंक्तियों के साथ समय स्लॉट. जब मैं दृश्य प्रदर्शित करने के लिए मेरे macos स्क्रीन, यह कुछ इस तरह दिखता है:
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
लेकिन जब मैं इसे प्रिंट, यह truncates कुछ है, लेकिन जरूरी नहीं कि सब के सब दो-पंक्ति पाठ आइटम की तरह है, तो:
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
अगर तुम नोटिस विसंगति, कि है, क्योंकि यह नहीं है पूरी तरह से संगत है । कभी कभी मैं दो लाइन उत्पादन, लेकिन अधिक बार मैं ट्रंकेशन के साथ अंडाकार. मैं बाहर सोचा नहीं किया है के अंतर्निहित पैटर्न क्यों । लेकिन केवल प्रिंट फ़्रेम है, यह एक समस्या है । स्क्रीन प्रदर्शित कर रहा है वास्तव में मैं क्या चाहते हैं.
तो मैं शिकार के चारों ओर समाधान के लिए, और करने की कोशिश की है के कई रूपों पाठ() संशोधक fixedSize() और lineLimit(). fixedSize की तरह काम करता है, में है कि दो-पंक्ति आइटम नहीं काटना है, लेकिन फिर से, प्रिंट में देखने के लिए, पंक्ति के साथ लंबा सेल क्लिप्स पंक्तियों के ऊपर और नीचे । यह वास्तव में की तरह अभिनय NSRect को तैयार करने के लिए प्रिंट छवि बस काफी बड़ा नहीं है, लेकिन यह बहुत बड़ा है, और यह नहीं हो जाना चाहिए.
परियोजना बहुत बड़ा है प्रदान करने के लिए सभी कोड है, लेकिन उम्मीद है कि यह पर्याप्त होगा प्रदान करने के लिए देखने में सवाल, प्लस प्रिंटर तर्क है.
देखें (यह सही ढंग से प्रदर्शित करता है - कोई truncation):
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)
}
}
}
}
}
}
और यहाँ मुद्रण समारोह है । यह अभी भी कमी है पृष्ठ पर अंक लगाना कार्यक्षमता, लेकिन यह है कि मैं क्या मिल गया है अब तक:
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()
}