我正在使用 Haskell cairo 系結繪制圖紙,我想垂直對齊一些物件。為此,我需要知道這些物件的寬度(邊界框或部分)。
我試圖通過這個技巧來得到它:
(origx,origy) <- getCurrentPoint -- Get the origins coordinates
setSourceRGBA 0 0 0 0 -- Make the rest of the rendering transparent
renderMyObject -- Rendering the object
(endx,endy) <- getCurrentPoint -- Get the final coordinates
let width = endx - origx -- Get the width of the object
...
translate width 0 -- Positioning according to width
setSourceRGB 1 0 0 -- Give the final color
renderMyObject -- Rendering the object
這種方法的問題是,如果我在物件的渲染中進行顏色更改并且寬度的計算不適用于所有物件,則它無法作業。
cairo 有沒有辦法在作業表面或虛擬表面上進行“幻像”渲染并檢索物件/表面的寬度和高度?
注意:我知道圖表庫允許這樣做,但出于兼容性原因,我不能在這個專案中使用它。但如果你知道圖書館是怎么做的,我很感興趣。
uj5u.com熱心網友回復:
開羅沒有辦法做到這一點。你基本上有兩個選擇:
- 強制執行特定大小。您可以使用
withImageSurface設定最大寬度和高度,并在生成的表面上進行所有繪圖。任何出界的東西都會被簡單地扔在地板上。 - 計算大小。在渲染時,記下您所做的每個繪圖操作的范圍,并在進行時將它們組合起來。使您的渲染操作將組合范圍回傳給呼叫者。
該diagrams軟體包選擇后者。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/465871.html
上一篇:AzureServiceBusJMS庫是否支持托管標識?
下一篇:Haskell嵌入式
