ทำไมของฉัน NSPrintOperation พิมพ์ภาพ truncating ของข้อความ()ในมุมมองแต่ของจอภาพของภาพคือแสดงคนเดียวกันข้อความมุมมองได้ดี

0

คำถาม

คนแรกฉันต้องขอโทษด้วยที่มันไม่มีภาพถ่ายต่างๆทั้งนี้ เห็นได้ชัดว่าฉันยังคงเหมือนกันใหม่ที่นี่เพื่อทำอย่างนั้น ฉันจะพยายามอธิบายปัญหาของการพูดและข้อสองคนกุญแจชิ้นส่วนของรหัสมอส

ฉันกำลังพิมพ์ทีวีจัดตารางกับวนแถวขอเวลาล็อต ตอนที่ฉันแสดงมุมมองของฉั 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

ถ้าคุณสังเกตเห็น inconsistency นั่นเป็นเพราะว่ามันไม่ค่อยสอดคล้องกันนะ บางครั้งฉันทำให้ทั้งสองคนเส้นผลส่งออกแต่อีกบ่อยฉันไป truncation กับ ellipsis. ผมยังคิดไม่ออกจาก underlying รูปแบบแล้วว่าทำไม แต่เดียวที่อยู่ในพิมพ์เฟรมนี่คือปัญหาแล้ว ที่หน้าจอแสดงสิ่งที่ฉันต้องการ

ดังนั้นฉันต้องถูกตามล่าอยู่ทางแก้ปัญหานั่นและพยายามมากในการเต้นของข้อความ()แก้ไขล่าสุด: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)
                    }
                }
            }
        }
    }
}

และนี่คือการพิมพ์ฟังก์ชัน. มันยังคงขาดไปอ pagination functionality แต่มันเป็นสิ่งที่ฉันมีดังนั้นห่างไกล:

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()
    
}
printing swift truncation view
2021-11-23 17:18:45
1

คำตอบที่ดีที่สุด

0

ปัญหาคือเกี่ยวข้องกับของฉันใช้ของมุมมองรายการ. มันดูเหมือนขีดจำกัดของทางแนวตั้งเลื่อนหน้าต่างบางอย่าได้นำเข้ามาในเครื่องพิมพ์ฟังก์ชันและบีบพิมพ์ภาพทางแนวตั้งอวกาศ ดังนั้นนั่นคือเหตุผลว่าทำไมถึงมีนเป็นเรื่องความแตกต่างระหว่างหน้าจอกับต้องการเครื่องพิมพ์รุ่นของคนเดียวกันมุมมอง ฉันซ่อมมันโดนแทนที่รายการด้ว VStack. ไม่มากไปก truncation กำลังจะเกิดขึ้น

2021-11-24 19:37:48

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่