2017-03-17 43 views
0

我使用Win API調用(多邊形)在Delphi中使用可選孔填充填充區域。通過裁剪區域來切割孔(不填充bg顏色)。它可以正常工作,直到我打印預覽(並且打印預覽看起來很好,直到預覽頁面不包含帶孔的填充區域)。打印預覽中的頁面內容由填充區域的相同方法調用繪製,就在調用在dc上設置的紙張尺寸縮放和裁剪區域之前。填充區域對象的繪製方法不會將自己的裁剪操作與頁面裁剪相結合。如何才能在頁面切割夾和其他切割夾之間進行AND操作(切割孔應該是彼此相關的)。如何在主剪切區域和其他剪切區域之間進行「與」運算?

的FilledArea對象繪製方法(只是裁剪特定行):

... 
try 
    if (fHoles^.getCount > 0) then 
    begin 
    // Get a copy of the page clipping rgn 
    getClipRgn(dc, rgnPrev); 
    for i := 0 to fHoles^.getCount-1 do 
    begin 
     ... 
     // create a rgn to the Xth hole 
     rgn := createPolygonRgn(rgnPts^, rgnPtsCount, ALTERNATE); 
     if (rgn <> 0) then 
     begin 
     // combine the Xth rgn with the active rgn (OR because there could be many holes in a single filled area) 
     extSelectClipRgn(dc, rgn, RGN_DIFF); 
     // releases the Xth rgn 
     deleteObject(rgn); 
     end; 
     ... 
    end; 
    end; 
    // draw the polygon 
finally 
    if (fHoles^.getCount > 0) then 
    begin 
    // selects a copy of the page cutting rgn copy 
    selectClipRgn(dc, rgnPrev); 
    // releases the copy of the page cutting rgn 
    deleteObject(rgnPrev); 
    end; 
end; 

打印預覽裁剪區域的繪圖代碼:

// Creates a page clipping rgn 
rcRegion := createRectRgn(rcDevLeft_, rcDevTop_, rcDevRight_ + 2, rcDevBottom_ + 2); 
try 
    // Selects a copy of the page clipping rgn 
    selectClipRgn(dc_, rcRegion); 
    ... 
    // draw the page contents 
    ... 
finally 
    // Selects an empty clipping rgn 
    selectClipRgn(dc_, 0); 
    // Releases the created page clipping rgn 
    deleteObject(rcRegion); 
end; 

甲設計時屏幕快照從填充區域具有兩個孔: enter image description here

打印預覽屏幕截圖從同一設計(移動的輪廓線標誌着第e頁面切割區域被忽略,內容由於兩頁而被兩次繪製) enter image description here

+0

這是無法理解的。 –

+0

@SertacAkyuz你不瞭解什麼? –

+0

你在做什麼。演示圖形可以很好。然後你可能還需要一個[MCVE]。 –

回答

0

OK。我找到了。我應該使用combineRgn Win API調用來定義兩個傳入區域之間的Boole操作。