473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VBA function for rounded pdf rectangles

The following Access VBA function creates a string that can be used in
a pdf stream to draw or fill a rectangle of a given color with rounded
corners:

'Begin code-----------
Public Function DrawRoundedRectangle(dblX As Double, dblY As Double, _
dblR As Double, dblW As Double, dblH As Double, _
dblThickness As Double, dblLineR As Double, dblLineG _
As Double, dblLineB As Double, boolFill As Boolean, dblFillR _
As Double, dblFillG As Double, dblFillB As Double) As String
Dim strTemp As String
Dim strCR As String
'C1 = 1 - 4 * (SQRT(2) - 1) / 3 (used for 1/4 circle Bezier Curves)
'As shown in http://www.tinaja.com/glib/bezcirc.pdf
Const C1 = 0.447715

'dblX = X coordinate of LL of rounded rectangle in points
'dblY = Y coordinate of LL of rounded rectangle in points
'dblR = Radius of rounded corners in points
'dblH = Height of rounded rectangle in points
'dblW = Width of rounded rectangle in points
'dblThickness = Thickness of line used to draw the rounded _
rectangle in points
'dblLineR = Red component of line color 0.0 to 1.0
'dblLineG = Green component of line color 0.0 to 1.0
'dblLineB = Blue component of line color 0.0 to 1.0
'boolFill = Fill the rectangle when True, Draw the outline when False
'dblFillR = Red component of fill color 0.0 to 1.0
'dblFillG = Green component of fill color 0.0 to 1.0
'dblFillB = Blue component of fill color 0.0 to 1.0
strCR = Chr(13)
strTemp = "%Rounded Rectangle" & strCR
strTemp = strTemp & "q" & strCR
strTemp = strTemp & CStr(dblThickness) & " w" & strCR
strTemp = strTemp & CStr(dblLineR) & " " & CStr(dblLineG) & " " _
& CStr(dblLineB) & " RG" & strCR
If boolFill Then
'h = ClosePath operator
strTemp = strTemp & "h" & strCR
strTemp = strTemp & CStr(dblFillR) & " " & CStr(dblFillG) & " " _
& CStr(dblFillB) & " rg" & strCR
End If
strTemp = strTemp & CStr(Round(dblR + dblX, 6)) & " " _
& CStr(dblY) & " m" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW - dblR, 6)) _
& " " & CStr(dblY) & " l" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW - C1 * dblR, 6)) & " " _
& CStr(dblY) & " " & CStr(Round(dblX + dblW, 6)) & " " _
& CStr(Round(dblY + C1 * dblR, 6)) & " " _
& CStr(Round(dblX + dblW, 6)) _
& " " & CStr(Round(dblY + dblR, 6)) & " c" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW, 6)) & " " _
& CStr(Round(dblY + dblH - dblR, 6)) & " l" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW, 6)) & " " _
& CStr(Round(dblY + dblH - C1 * dblR, 6)) & " " _
& CStr(Round(dblX + dblW - C1 * dblR, 6)) & " " _
& CStr(Round(dblY + dblH, 6)) & " " _
& CStr(Round(dblX + dblW - dblR, 6)) & " " _
& CStr(Round(dblY + dblH, 6)) & " c" & strCR
strTemp = strTemp & CStr(Round(dblX + dblR, 6)) & " " _
& CStr(Round(dblY + dblH, 6)) & " l" & strCR
strTemp = strTemp & CStr(Round(dblX + C1 * dblR, 6)) _
& " " & CStr(Round(dblY + dblH, 6)) & " " _
& CStr(dblX) & " " & CStr(Round(dblY + dblH - C1 * dblR, 6)) & " " _
& CStr(dblX) & " " & CStr(Round(dblY + dblH - dblR, 6)) & " c" & strCR
strTemp = strTemp & CStr(dblX) & " " _
& CStr(Round(dblY + dblR, 6)) & " l" & strCR
strTemp = strTemp & CStr(dblX) & " " _
& CStr(Round(dblY + C1 * dblR, 6)) & " " _
& CStr(Round(dblX + C1 * dblR, 6)) _
& " " & CStr(dblY) & " " & CStr(Round(dblX + dblR, 6)) _
& " " & CStr(dblY) & " c" & strCR
If boolFill Then
'f = Fill operator
strTemp = strTemp & "h f" & strCR
Else
strTemp = strTemp & "S" & strCR
End If
strTemp = strTemp & "Q" & strCR
DrawRoundedRectangle = strTemp
End Function

Function Round(varIn As Variant, intPlaces As Integer) As Variant
Round = Int(10 ^ intPlaces * varIn + 0.5) / 10 ^ intPlaces
End Function
'End code-------------

Perhaps someone will find it useful. BTW, the output from this
function can be assigned to strStream in:

http://groups-beta.google.com/group/...8ab160cf?hl=en

which would in effect make the single pdf page a canvas for any of the
pdf drawing operators. I suppose I should make some of the function's
arguments optional. This function has worked in all the situations I
have tried but use at your own risk, etc. Note: I didn't test out the
normal rounded rectangle without fill after adding in the code for
optional filling. I'll post back if the fill code broke the non-fill
case. I specified two sets of colors in case I want to put a border
with a different color around the filled rectangle someday.

James A. Fortune

Nov 13 '05 #1
1 3567
ji********@compumarc.com wrote:
...
case. I specified two sets of colors in case I want to put a border
with a different color around the filled rectangle someday.


By simply replacing the "h f" string (closepath, fill) near the end of
the function with "b" (closepath, fill, stroke) I was able to get the
filled rectangle with a border in a different color.

James A. Fortune

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double...
3
by: cai_rongxi | last post by:
Hi, Can some body share the code to find the intersection of two rectangles? Thanks in advance
9
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
0
by: Fir5tSight | last post by:
Hi All, Again I apologize for posting this topic at the wrong forum, because I don't know where else I can get help on this matter. This is about invisible lines and rectangles in a PDF file....
7
by: ddecoste | last post by:
I have a need to add a visual representation to some data in Access. I need to draw a matix of squares inside another square. I have all the data that I need in a record in Access. The data...
3
by: anupamsps | last post by:
HI all, This is my first posting in this forum. I am confused about how to write a function that returns a value rounded to the nearest value of a double variable say X. when X is positive...
9
by: active | last post by:
I need a control that displays a grid of rectangles. That is, like a brick wall except the rectangles are lined up. In VB6 I used such a control (may have been called FlexGrid but I'm not...
3
by: cowboyrocks2009 | last post by:
Hi, I am trying to write a Java program to plot rectangles with different colors side by side non overlapping but unfortunately I am unable to do that as of now. Suppose I want to create 3...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.