1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
| Option Explicit
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Const LF_FACESIZE = 32
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long ' or Boolean
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As TEXTSIZE) As Long
Private Type TEXTSIZE
X As Long
Y As Long
End Type
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName As String * LF_FACESIZE
End Type
'Position du texte :
Public X As Integer, Y As Integer
Public Angle As Integer
Public Split As Boolean
Public Face As Integer
' Signification particuliere de Face et Split pour le texte :
'
' Split = False
' Face = 1 : Texte en CU1, lisible quand on regarde le côté cuivre 1
' Face = 2 : Texte en CU2, lisible quand on regarde le côté cuivre 2
' Face = 3 : Texte en CU1 et CU2, lisible quand on regarde chaque côté
'
' Split = True
' Face = 1 : Texte en CU1, lisible par transparence quand on regarde de l'autre côté
' Face = 2 : Texte en CU2, lisible par transparence quand on regarde de l'autre côté
' Face = 3 : Texte en CU1 et CU2, lisible quand on regarde chaque côté (idem split = false)
'Texte :
Public Valeur As String
'Mode de texte :
Public Lien As Integer
'Police de caractère :
Public FName As String
Public FSize As Single
Public FBold As Boolean
Public FItalic As Boolean
Public FStrikethru As Boolean
Public FUnderline As Boolean
Public FTransparent As Boolean
'Vrai si l'objet est sélectionné :
Public Selected As Boolean
Public Sub Dess(Ctrl, Couleurs() As Long, Layers() As Boolean, Echelle As Single, BarreX As Integer, BarreY As Integer, XAmin As Integer, YAmin As Integer, XAmax As Integer, YAmax As Integer)
Dim CoulNoire As Long
Dim Retourne As Boolean
Dim TxtH As Integer
Dim TxtW As Integer
Dim TempX1 As Integer, TempY1 As Integer
Dim TempX2 As Integer, TempY2 As Integer
Dim TempX3 As Integer, TempY3 As Integer
Dim TempX4 As Integer, TempY4 As Integer
Dim COSS As Single
Dim SINS As Single
Dim SX As Integer, SY As Integer
'---------
Dim font As LOGFONT
Dim prevFont As Long
Dim hFont As Long
Dim ret As Long
'---------
Select Case Face
Case 3:
Retourne = False
CoulNoire = Couleurs(4) 'CU1 et CU2
Case 2:
Retourne = False
CoulNoire = Couleurs(1) 'CU2
Case 1:
Retourne = True
CoulNoire = Couleurs(0) 'CU1
End Select
'MISE A JOUR DE VALEUR :
If Lien = 0 Then Valeur = Data_Auteur
If Lien = 1 Then Valeur = Data_Mail
If Lien = 2 Then Valeur = Data_Organisation
If Lien = 3 Then Valeur = Data_Siteweb
If Lien = 4 Then Valeur = Data_Projet
If Lien = 5 Then Valeur = Data_Carte
If Lien = 6 Then Valeur = Data_Date
If Lien = 7 Then Valeur = Data_Version
'MODIFICATION : FSIZE est maintenant en pixels
If (Face = 1 And Layers(0)) Or (Face = 2 And Layers(1)) Or (Face = 3 And (Layers(0) Or Layers(1))) Then
'Calcul de la taille du texte :
Ctrl.FillColor = CoulNoire
Ctrl.ForeColor = CoulNoire
'En règle générale, vous devrez modifier la propriété FontName avant de définir les
'attributs de taille et de style à laide des propriétés FontSize, FontBold, FontItalic,
'FontStrikethru et FontUnderline. Toutefois, si vous affectez aux polices TrueType une
'taille inférieure à 8 points, vous devrez commencer par définir la taille à laide de la
'propriété FontSize, puis définir la propriété FontName, et enfin redéfinir la taille à
'laide de la propriété FontSize. En effet, lenvironnement Microsoft Windows utilise une
'police différente pour les polices TrueType dont la taille est inférieure à 8 points.
'1 point de police = 1/72ième de pouce
'FSize est en "pixels écran" :
Ctrl.FontSize = FSize * Echelle * Screen.TwipsPerPixelY / (20 * CoefZoom1N)
Ctrl.FontName = FName
Ctrl.FontBold = FBold
Ctrl.FontItalic = FItalic
Ctrl.FontStrikethru = FStrikethru
Ctrl.FontUnderline = FUnderline
Ctrl.FontTransparent = FTransparent
Ctrl.FontSize = FSize * Echelle * Screen.TwipsPerPixelY / (20 * CoefZoom1N)
Debug.Print "Textecuivre " & Chr$(34) & Valeur & Chr$(34) & " " & Format(FSize) & "pixels -> " & Format(Ctrl.FontSize) & "points = " & Format(FSize * Echelle * Screen.TwipsPerPixelY / (20 * CoefZoom1N))
TxtW = Ctrl.TextWidth(Valeur)
TxtH = Ctrl.TextHeight(Valeur)
SX = TxtW / (2 * Echelle)
SY = TxtH / (2 * Echelle)
'Calcul des coordonnées :
COSS = Cos(-Angle * 1.74532925199433E-02)
SINS = Sin(-Angle * 1.74532925199433E-02)
TempX1 = X - SX * COSS + SY * SINS
TempY1 = Y - SX * SINS - SY * COSS
TempX2 = X + SX * COSS + SY * SINS
TempY2 = Y + SX * SINS - SY * COSS
TempX3 = X - SX * COSS - SY * SINS
TempY3 = Y - SX * SINS + SY * COSS
TempX4 = X + SX * COSS - SY * SINS
TempY4 = Y + SX * SINS + SY * COSS
If Ctrl.DrawMode = 13 Then
'---------
' Windows expects the font size to be in pixels and to be negative if you are specifying the character height you want.
font.lfHeight = -FSize * Echelle / CoefZoom1N
Debug.Print " -> " & Format(font.lfHeight) & "pixels" & vbCrLf
'font.lfWidth
font.lfEscapement = Angle * 10
font.lfOrientation = Angle * 10
If FBold Then
font.lfWeight = 700
Else
font.lfWeight = 400
End If
font.lfItalic = FItalic
font.lfUnderline = FUnderline
font.lfStrikeOut = FStrikethru
'font.lfCharSet
'font.lfOutPrecision
'font.lfClipPrecision
'font.lfQuality
'font.lfPitchAndFamily
font.lfFaceName = FName & Chr$(0)
hFont = CreateFontIndirect(font)
prevFont = SelectObject(Ctrl.hdc, hFont)
'---------
Ctrl.CurrentX = (TempX1 - BarreX) * Echelle
Ctrl.CurrentY = (TempY1 - BarreY) * Echelle
Ctrl.FontTransparent = FTransparent
Ctrl.Print Valeur
'---------
' Clean up by restoring original font.
ret = SelectObject(Ctrl.hdc, prevFont)
ret = DeleteObject(hFont)
'---------
'******************* A DES FINS DE MISE AU POINT *******************
'Affichage du rectangle de sélection :
Ctrl.Line ((TempX2 - BarreX) * Echelle, (TempY2 - BarreY) * Echelle)-((TempX1 - BarreX) * Echelle, (TempY1 - BarreY) * Echelle)
Ctrl.Line ((TempX1 - BarreX) * Echelle, (TempY1 - BarreY) * Echelle)-((TempX3 - BarreX) * Echelle, (TempY3 - BarreY) * Echelle)
Ctrl.Line ((TempX4 - BarreX) * Echelle, (TempY4 - BarreY) * Echelle)-((TempX2 - BarreX) * Echelle, (TempY2 - BarreY) * Echelle)
Ctrl.Line ((TempX3 - BarreX) * Echelle, (TempY3 - BarreY) * Echelle)-((TempX4 - BarreX) * Echelle, (TempY4 - BarreY) * Echelle)
'Affichage de CurrentX et CurrentY :
Ctrl.FillColor = RGB(255, 50, 50)
Ctrl.ForeColor = RGB(255, 50, 50)
SX = 20
Ctrl.Line ((TempX1 - BarreX) * Echelle + SX, (TempY1 - BarreY) * Echelle)-((TempX1 - BarreX) * Echelle - SX, (TempY1 - BarreY) * Echelle)
Ctrl.Line ((TempX1 - BarreX) * Echelle, (TempY1 - BarreY) * Echelle + SX)-((TempX1 - BarreX) * Echelle, (TempY1 - BarreY) * Echelle - SX)
'Affichage de X et Y :
Ctrl.FillColor = RGB(50, 50, 255)
Ctrl.ForeColor = RGB(50, 50, 255)
Ctrl.Line ((X - BarreX) * Echelle + SX, (Y - BarreY) * Echelle)-((X - BarreX) * Echelle - SX, (Y - BarreY) * Echelle)
Ctrl.Line ((X - BarreX) * Echelle, (Y - BarreY) * Echelle + SX)-((X - BarreX) * Echelle, (Y - BarreY) * Echelle - SX)
'*******************************************************************
Else
'Il faut gérer le pb du draw mode avec le texte pour localiser le texte lors de l'édition :
Ctrl.Line ((TempX2 - BarreX) * Echelle, (TempY2 - BarreY) * Echelle)-((TempX1 - BarreX) * Echelle, (TempY1 - BarreY) * Echelle)
Ctrl.Line ((TempX1 - BarreX) * Echelle, (TempY1 - BarreY) * Echelle)-((TempX3 - BarreX) * Echelle, (TempY3 - BarreY) * Echelle)
Ctrl.Line ((TempX4 - BarreX) * Echelle, (TempY4 - BarreY) * Echelle)-((TempX2 - BarreX) * Echelle, (TempY2 - BarreY) * Echelle)
Ctrl.Line ((TempX3 - BarreX) * Echelle, (TempY3 - BarreY) * Echelle)-((TempX4 - BarreX) * Echelle, (TempY4 - BarreY) * Echelle)
End If
End If
End Sub
Public Sub Trace(Ctrl, Couleurs() As Long, Layers() As Boolean, Echelle As Double, DecalageX As Double, DecalageY As Double)
'Ctrl est le contrôle où tracer le composant
'
'Couleurs(0) est la couleur du layer CU1
'Couleurs(1) est la couleur du layer CU2
'Couleurs(2) est la couleur du layer SOL
'Couleurs(3) est la couleur du layer TXT
'Couleurs(4) est la couleur du layer CU1&2
'
'Layers(0) est vrai si on doit tracer le layer CU1
'Layers(1) est vrai si on doit tracer le layer CU2
'Layers(2) est vrai si on doit tracer le layer SOL
'Layers(3) est vrai si on doit tracer le layer TXT
'
'Les coordonnées graphiques sont :
'(X * Echelle + DecalageX, Y * Echelle + DecalageY)
Dim CoulNoire As Long
Dim cpt As Integer
Dim cx As Integer, cy As Integer
Dim Hyp As Single
Dim Retourne As Boolean
Dim TxtH As Double
Dim TxtW As Double
Dim TempX1 As Integer, TempY1 As Integer
Dim TempX3 As Integer, TempY3 As Integer
Dim TempX4 As Integer, TempY4 As Integer
Dim TempX5 As Integer, TempY5 As Integer
Dim TempX2 As Long, TempY2 As Long
Dim COSS As Single
Dim SINS As Single
Dim SX As Integer, SY As Integer
Dim FSizeImpr As Integer 'FSize en pixels imprimante
'---------
Dim font As LOGFONT
Dim prevFont As Long
Dim hFont As Long
Dim ret As Long
Dim PrinterHDC As Long
Dim TPP
'---------
Select Case Face
Case 3:
Retourne = False
CoulNoire = Couleurs(4) 'CU1 et CU2
Case 2:
Retourne = False
CoulNoire = Couleurs(1) 'CU2
Case 1:
Retourne = True
CoulNoire = Couleurs(0) 'CU1
End Select
'
'MISE A JOUR DE VALEUR :
If Lien = 0 Then Valeur = Data_Auteur
If Lien = 1 Then Valeur = Data_Mail
If Lien = 2 Then Valeur = Data_Organisation
If Lien = 3 Then Valeur = Data_Siteweb
If Lien = 4 Then Valeur = Data_Projet
If Lien = 5 Then Valeur = Data_Carte
If Lien = 6 Then Valeur = Data_Date
If Lien = 7 Then Valeur = Data_Version
'
If (Face = 1 And Layers(0)) Or (Face = 2 And Layers(1)) Or (Face = 3 And (Layers(0) Or Layers(1))) Then
FSizeImpr = FSize * Screen.TwipsPerPixelY / Ctrl.TwipsPerPixelY
'
Ctrl.FillColor = CoulNoire
Ctrl.ForeColor = CoulNoire
'FSizeImpr est en pixels imprimante :
Ctrl.FontSize = FSizeImpr * 50 * Echelle * Ctrl.TwipsPerPixelY
' = FSizeImpr * 1000 * Echelle * Ctrl.TwipsPerPixelY / 20
Ctrl.FontName = FName
Ctrl.FontBold = FBold
Ctrl.FontItalic = FItalic
Ctrl.FontStrikethru = FStrikethru
Ctrl.FontUnderline = FUnderline
Ctrl.FontTransparent = FTransparent
Ctrl.FontSize = FSizeImpr * 50 * Echelle * Ctrl.TwipsPerPixelY
Debug.Print "Textecuivre " & Chr$(34) & Valeur & Chr$(34) & " " & Format(FSize) & "pixels ecran -> " & Format(FSizeImpr) & "pixels imprimante -> " & Format(Ctrl.FontSize) & " = " & Format(FSizeImpr * 50 * Echelle * Ctrl.TwipsPerPixelY)
TPP = Ctrl.TwipsPerPixelY
Ctrl.Print ""
TxtW = Ctrl.TextWidth(Valeur) 'En pouces imprimés
TxtH = Ctrl.TextHeight(Valeur) 'En pouces imprimés
SX = TxtW / (2 * Echelle) 'Rayon selon X en unités
SY = TxtH / (2 * Echelle) 'Rayon selon Y en unités
'Calcul des coordonnées :
COSS = Cos(-Angle * 1.74532925199433E-02)
SINS = Sin(-Angle * 1.74532925199433E-02)
TempX1 = X - SX * COSS + SY * SINS
TempY1 = Y - SX * SINS - SY * COSS
TempX5 = X + SX * COSS + SY * SINS
TempY5 = Y + SX * SINS - SY * COSS
TempX3 = X - SX * COSS - SY * SINS
TempY3 = Y - SX * SINS + SY * COSS
TempX4 = X + SX * COSS - SY * SINS
TempY4 = Y + SX * SINS + SY * COSS
'Echelle = 0,001 pour une échelle d'impression de 100%
'COORDONNEES EN POUCE (PRINTER.SCALEMODE = 5) :
' Ctrl.CurrentX = DecalageX + TempX1 * Echelle
' Ctrl.CurrentY = DecalageY + TempY1 * Echelle
'L'API RECLAME DES COORDONNEES EN PIXEL :
' NB: Il y a 1440 Twips par pouce
' X.Pixels = X.Pouces * 1440 / TwipsPerPixel
TempX2 = (DecalageX + TempX1 * Echelle) * 1400 / Ctrl.TwipsPerPixelX
TempY2 = (DecalageY + TempY1 * Echelle) * 1400 / Ctrl.TwipsPerPixelY
'----------------- Impression du texte avec les API ---------------------
'On ne doit plus utiliser l'objet "Printer", il faut passer par le HDC de l'imprimante :
PrinterHDC = Printer.hdc 'Ctrl.hdc
'Initialisation de la police de caractère inclinée :
'Windows expects the font size to be in pixels and to be negative if you are specifying the character height you want.
font.lfHeight = FSizeImpr * (1000 * Echelle)
Debug.Print " -> " & Format(font.lfHeight) & "pixels imprimante = " & Format(FSize * 1000 * Echelle) & vbCrLf
'font.lfWidth
font.lfEscapement = Angle * 10
font.lfOrientation = Angle * 10
If FBold Then
font.lfWeight = 700
Else
font.lfWeight = 400
End If
font.lfItalic = FItalic
font.lfUnderline = FUnderline
font.lfStrikeOut = FStrikethru
'font.lfCharSet
'font.lfOutPrecision
'font.lfClipPrecision
'font.lfQuality
'font.lfPitchAndFamily
font.lfFaceName = FName & Chr$(0)
'
'Application de la police à l'imprimante :
hFont = CreateFontIndirect(font)
prevFont = SelectObject(PrinterHDC, hFont)
'
'Impression du texte :
ret = TextOut(PrinterHDC, TempX2, TempY2, Valeur, Len(Valeur))
'
'Suppression de la police sur l'imprimante :
ret = SelectObject(PrinterHDC, prevFont)
ret = DeleteObject(hFont)
'------------------------------------------------------------------------
'******************* A DES FINS DE MISE AU POINT *******************
'Les coordonnées graphiques sont :
'(X * Echelle + DecalageX, Y * Echelle + DecalageY)
'Affichage du rectangle de sélection :
Ctrl.Line (TempX5 * Echelle + DecalageX, TempY5 * Echelle + DecalageY)-(TempX1 * Echelle + DecalageX, TempY1 * Echelle + DecalageY)
Ctrl.Line (TempX1 * Echelle + DecalageX, TempY1 * Echelle + DecalageY)-(TempX3 * Echelle + DecalageX, TempY3 * Echelle + DecalageY)
Ctrl.Line (TempX4 * Echelle + DecalageX, TempY4 * Echelle + DecalageY)-(TempX5 * Echelle + DecalageX, TempY5 * Echelle + DecalageY)
Ctrl.Line (TempX3 * Echelle + DecalageX, TempY3 * Echelle + DecalageY)-(TempX4 * Echelle + DecalageX, TempY4 * Echelle + DecalageY)
'Affichage de CurrentX et CurrentY :
Ctrl.FillColor = RGB(255, 50, 50)
Ctrl.ForeColor = RGB(255, 50, 50)
Hyp = 0.1
Ctrl.Line (TempX1 * Echelle + DecalageX + Hyp, TempY1 * Echelle + DecalageY)-(TempX1 * Echelle + DecalageX - Hyp, TempY1 * Echelle + DecalageY), RGB(255, 50, 50)
Ctrl.Line (TempX1 * Echelle + DecalageX, TempY1 * Echelle + DecalageY + Hyp)-(TempX1 * Echelle + DecalageX, TempY1 * Echelle + DecalageY - Hyp), RGB(255, 50, 50)
'Affichage de X et Y :
Ctrl.FillColor = RGB(50, 50, 255)
Ctrl.ForeColor = RGB(50, 50, 255)
Ctrl.Line (X * Echelle + DecalageX + Hyp, Y * Echelle + DecalageY)-(X * Echelle + DecalageX - Hyp, Y * Echelle + DecalageY), RGB(50, 50, 255)
Ctrl.Line (X * Echelle + DecalageX, Y * Echelle + DecalageY + Hyp)-(X * Echelle + DecalageX, Y * Echelle + DecalageY - Hyp), RGB(50, 50, 255)
'*******************************************************************
End If
End Sub |
Partager