"Schmidt" <sss@online.de> escribió en el mensaje
news:jrlvu0$pac$1@dont-email.me...
> Am 17.06.2012 23:29, schrieb Eduardo:
>
> [PDF-Rendering]
>> So... I was thinking about, perhaps writing such a component.
>
> A huge task (regarding implementation of correct PDF-Output),
Yes, I know, that's why I said "perhaps" (I would write it).
> ...and already done in a decent way by the cairo-developers.
I didn't know.
> (and again, as for your DB-FullText-Search - contained in RC4).
>
> So in case you are intereseted, I could come up with
> (simple) examples, to get you going.
OK, great.
I have routines for printing that use code like:
Printer.FontName...
Printer.Orientation...
Printer.CurrentX...
Printer.Print...
Printer.Line...
>
> Cairo is nice for that, because you can work against
> always the same CairoContext-Interface (something like a
> hDC in the Windows-GDI). You can use the very same drawing
I think that in some parts I have used API calls also, TextOut or DrawText
over the printer's hDC
> methods for an OnScreen-Preview ("PixelSurface-Rendering") -
> as when rendering with your unchanged Routines (using the
> same coordinates!) against a PDF-based CairoContext.
>
> In case the CairoContext came from a normal PixelSurface,
> you can render this Surface later on (after all your
> Drawing-Output-Routines did their work) to your VB-Form.hdc
> in a single call:
> PxlSurface.DrawTo Form.hDC, xOffs, yOffs
Could this be useful to make a print preview in a PictureBox?
>
> And in case the CairoContext came from a PDF-Surface, your
> same Drawing-Routines will not "change Pixels on it" of course,
> but write (under the hood) the appropriately translated PDF-
> Commands directly into a File instead.
So far I just would like to use the code that I have for the printer object.
>
>
>> But, I should use the same interface that the VB Printer object uses,
>> so the user should just change "Printer" to "mPrinter" and declare
>> mPrinter as object, and set that variable to an instance of my Class.
>>
>> But, I found that I can declare a Sub Line, but not a sub Print,
>> Circle or PSet.
>
> The one Problem is the Naming (you would need to use a
> TypeLib-Defintion, to allow Names as Class-Methods, which
> are already "reserved" by VB).
>
> On Top of that (even when VB would allow to define such
> names as Class-methods in an easy way directly) ... how would
> you solve the weird syntax-problem these "oldfashioned" methods
> (or perhaps: "statements") expect with regards to their Parameters?
>
> e.g. Line:
> Line (0, 200) - (ScaleWidth, 200), vbBlack
I already found how to solve that:
Public Sub Line(ParamArray nParams())
Try this:
New project, add a class module
In the class module:
Public Sub Line(ParamArray nParams())
Dim c As Long
For c = 0 To UBound(nParams)
Debug.Print "Parameter " & c & ": " & nParams(c)
Next c
End Sub
In the form:
Private Sub Form_Load()
Dim a As New Class1
a.Line (2, 3)-(4, 5), vbRed, BF
End Sub
The parameter BF comes in the first parameter ( index 0).
The object browser shows the definition:
Sub Line(Flags As Integer, X1 As Single, Y1 As Single, X2 As Single, Y2 As
Single, Color As Long)
>
> Not really a "normal" Function-Call, is it?
> Your own Line-Method would be defined with 5 Params instead
> (or an Optional six'th, for the "BF" Option-stuff, which is
> also there).
>
> e.g. (simplified) this way:
> Public Sub Line(x1, y1, x2, y2, Color, Optional Mode)
>
> which would require a change in your drawing-routines
> from:
> Printer.Line (0, 200) - (ScaleWidth, 200), vbBlack
> to:
> mPrinter.Line 0, 200, ScaleWidth, 200, vbBlack
>
> So, it would by no means be that easy, to reuse existing
> drawing-code, which has its Line-Drawing "expressed" in
> the old (backward-compatible) "Basic-Syntax", when putting
> a new (redefined with "real" Params) Line-Method behind a
> new Class (even when the Name-Definition-Problem for "Line"
> wouldn't exist).
>
> You would perhaps use the VB-IDE-Replace-Dialog, to solve that
> in a sequence of "well-thought" commands as e.g.:
> Replace all occurences of:
> '.Line ('
> with the term:
> '.Line '
>
> or:
> ') - ('
> with the term:
> ', '
>
> and so on...
> (although the last example is already ambigous, because you could
> replace such a sequence accidentally also in a subtraction-Op,
> which has sub-terms enclosed in parentheses as well).
>
> So, due to the "old-syntax" - you would need to run replacement-
> Ops on your old code in either way, so why not redefine at this
> occasion also the Naming?
>
> Replace all occurences of:
> '.Line ('
> with the term:
> '.DrawLine '
>
> ..and your Naming-Problem is already done (for the Line-Call).
> (I'm aware, that the Line-Call does not have that Naming-problem,
> but the same Problem with the weird Param-Definitions also
> exists for the Circle-Call and for PSet).
>
>> Besides that, I'm thinking now that I would run into trouble if the code
>> of
>> the program uses the hDc of the Printer to write or paint with APIs.
>> That's
>> another issue.
>
> When you work with a CairoContext, this is not a Handle,
> but (when working over the COM-Wrapper), is already a
> "Device-abstracting" Class-Encapsulation - and so IMO
> basically the thing you want to write on your own.
>
> A context can generate output in a PixelSurface
> (a PixelSurface is memory-wise similar to a GDI-DIB
> with 32Bit-per-Pixel - but doesn't consume a hDIB-Handle,
> it's just a plain mem-alloc)
>
> Dim PxlSrf As cCairoSurface
> Set PxlSrf = Cairo.CreateSurface(PxlWidth, PxlHeight, ImageSurface)
>
> or when creating a PDF-Surface:
> Dim PDFSrf As cCairoSurface
> Set PDFSrf = Cairo.CreateSurface(PdfPgWidth, PdfPgHeight, PDFSurface)
>
> In both cases of Surface-Types (which are hosted in the same
> Class-Type cCairoSurface) you can derive a CairoContext
> (the thing you will use for drawing), with a simple call:
>
> Dim CC as cCairoContext
> Set CC = PxlSrf.CreateContext
> 'or alternatively
> 'Set CC = PdfSrf.CreateContext
>
> This CC-Class-Variable (although representing something
> like a hDC) is of course a Class - and as such you don't
> need to initiate drawings over it, by giving a Handle
> into a "C-style API-Function" as e.g.:
> TextOut hDC, ..., ...
> Rectangle hDC, ..., ...
>
> But you do:
> CC.TextOut ..., ...
> CC.Rectangle ..., ...
> CC.DrawLine ..., ...
> 'etc for loads of additional drawing-functionality
>
> So, as said, your abstraction-Helper-Class (for both, Screen-
> and PDF-Output) is already there, in case you want to use
> the RC4-lib anyways (in its function as wrapper for SQLite).
>
> Maybe write a small additional wrapper around it, to allow
> also for the Color-Parameters the VB-Drawing-stuff offers
> directly in its old statements - and to support Properties
> as .Scalemode, .CurrentX, .CurrentY, in case you made heavy
> use of those in your drawing-routines as well.
I could write a class to make the conversion from the VB Printer syntax to
the Cairo syntax...