Module: Metodos
- Defined in:
- lib/imposition/metodos.rb
Class Method Summary collapse
-
.booklets(pagsEnCuadernillo, paginas, paginasReal, q) ⇒ Object
agrupa en cuadernillos.
- .checksCompile ⇒ Object
- .checksRun(entrada, salida) ⇒ Object
- .cortarCola(nPaginas, pagsEnCuadernillo, cuadernillosPorCostura) ⇒ Object
- .cutStack(nX, nY, nPaginas, nPliegos, w, h) ⇒ Object
-
.funcionar(w_, h_, wP_, hP_, nX, nY, nPaginas, nPliegos, cuadernillos, preguntas, temp) ⇒ Object
WORK.
-
.getCoordinates(nX, nY, w, h) ⇒ Object
TODO podria eliminar w y h haciendo la comparacion en base a n y k?.
-
.imponerBooklet(impostor, temp) ⇒ Object
TODO 1 sola vez pdflatex?.
- .imponerStack(impostor, temp) ⇒ Object
-
.input2alchemist(unidad) ⇒ Object
TODO validar que unidad exista en alchemist.
-
.mult4(paginasEnPliego) ⇒ Object
multiplo de 4.
- .myPlacePDF(nX, nY, nPaginas, nPliegos) ⇒ Object
-
.nuevo(valor, unidad) ⇒ Object
forma hash de variable para impostor.
- .ordenar(mix) ⇒ Object
-
.pagesize(pdfinfo) ⇒ Object
tamaño de página.
- .paginasdelpdf(pdfinfo) ⇒ Object
- .pdfinfo(impostor, temp) ⇒ Object
-
.pdflatexUnit(x, unidad) ⇒ Object
conversion unidades alchemy 2 pdflatex.
-
.redondear(n) ⇒ Object
por BUG de alchemist (ruby 1.9 tiene round(3)).
-
.refresh ⇒ Object
permite globales porque se encapsula logica de test y ejecutable.
-
.unaDentroDeOtra(paginasReal, paginasEnCuadernillo, inicio, fin) ⇒ Object
crea un cuadernillo.
- .validacion(impostor, preguntas) ⇒ Object
Class Method Details
.booklets(pagsEnCuadernillo, paginas, paginasReal, q) ⇒ Object
agrupa en cuadernillos
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/imposition/metodos.rb', line 391 def self.booklets(pagsEnCuadernillo, paginas, paginasReal, q) arreglo=[] van=0 for i in 0...(paginas.to_f/pagsEnCuadernillo).ceil if i!=0 then van+=pagsEnCuadernillo end inicio=van+1 fin=van+pagsEnCuadernillo if fin>paginas and q!=nil then pagsEnCuadernillo=q fin=van+q end booklet=unaDentroDeOtra(paginasReal, pagsEnCuadernillo, inicio, fin) arreglo.concat(booklet) end return arreglo end |
.checksCompile ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/imposition/metodos.rb', line 18 def checksCompile() #paquetes necesarios $requerimientos.each do |k,v| `which #{v}` if !$?.success? then return Clases::Mensaje.new(3,"#{v} no es ejecutable") end end #probamos que exista el directorio de trabajo if File.exists?($work) then #y que sea escribible if File.writable?($work) and File.writable_real?($work) then $work+="/impostor" if !File.exists?($work) then Dir.mkdir($work) end else return Clases::Mensaje.new(3,"el directorio de trabajo "+$work+" no se puede escribir") end else return Clases::Mensaje.new(3,"el directorio de trabajo "+$work+ " no existe") end end |
.checksRun(entrada, salida) ⇒ Object
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 |
# File 'lib/imposition/metodos.rb', line 42 def checksRun(entrada,salida) #la entrada if entrada != nil then if File.file?(entrada) then if File.owned?(entrada) then busca = /.*(.pdf)/ if !busca.match(File.basename(entrada)) then return Clases::Mensaje.new(3,"el archivo "+entrada+" no es pdf") end else return Clases::Mensaje.new(3,"el archivo "+entrada+" no es mío") end else return Clases::Mensaje.new(3,entrada+" no es un archivo") end else return Clases::Mensaje.new(3,"no ha especificado archivo a imponer") end #y la salida, de haberla if salida!=nil then #if File.exists?(salida) then #TODO crearla si es escribible salidaDir=File.dirname(salida) if !File.writable?(salidaDir) or !File.writable_real?(salidaDir) then return Clases::Mensaje.new(3,"el directorio de salida "+salida+" no se puede escribir") end #else # puts salida+ " no existe" # exit #end end end |
.cortarCola(nPaginas, pagsEnCuadernillo, cuadernillosPorCostura) ⇒ Object
423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/imposition/metodos.rb', line 423 def self.cortarCola(nPaginas, pagsEnCuadernillo, cuadernillosPorCostura) max = (nPaginas.to_f/pagsEnCuadernillo.to_f).ceil if max*pagsEnCuadernillo>nPaginas then anterior=pagsEnCuadernillo*(max-1) q=nPaginas-anterior if q%4!=0 then q=((q/4)+1)*4 end if anterior+q < max*pagsEnCuadernillo then return Clases::PreguntaReducir.new(cuadernillosPorCostura, max*pagsEnCuadernillo-nPaginas, q/4, (anterior+q)-nPaginas, q) end end end |
.cutStack(nX, nY, nPaginas, nPliegos, w, h) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/imposition/metodos.rb', line 328 def self.cutStack(nX,nY,nPaginas,nPliegos,w,h) coordenadas=getCoordinates(nX,nY,w,h) posiciones=myPlacePDF(nX,nY,nPaginas,nPliegos) remix=[] for i in 0...posiciones.size mix=Clases::Mix.new(posiciones[i].mC, coordenadas[posiciones[i].mP].x, coordenadas[posiciones[i].mP].y, posiciones[i].t) remix.insert(i, mix) end remix=ordenar(remix) retorno=[] #retorna solo el orden for i in 0...remix.length retorno << remix[i].n end return retorno end |
.funcionar(w_, h_, wP_, hP_, nX, nY, nPaginas, nPliegos, cuadernillos, preguntas, temp) ⇒ Object
WORK
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/imposition/metodos.rb', line 4 def funcionar(w_,h_,wP_,hP_,nX,nY,nPaginas,nPliegos,cuadernillos,preguntas,temp) impostor=Clases::Imposicion.new(w_,h_,wP_,hP_,nX,nY,nPaginas,nPliegos,cuadernillos) pdfinfo(impostor,temp) retorno=validacion(impostor, preguntas) if retorno.preguntasOk then retorno.mensajes.push(Clases::MensajeVars.new(1,impostor.to_s)) if impostor.cuadernillos then retorno.mensajes.push(imponerBooklet(impostor,temp)) end retorno.mensajes.push(imponerStack(impostor,temp)) end return retorno end |
.getCoordinates(nX, nY, w, h) ⇒ Object
TODO podria eliminar w y h haciendo la comparacion en base a n y k?
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 |
# File 'lib/imposition/metodos.rb', line 277 def self.getCoordinates(nX,nY,w,h) coordenadas=[] #posibilidad de usar márgenes x0=0 y0=0 xN=x0+w*(nX-1) i=0 k=0#posicion en n=0#fila while(i<nX*nY) do #USO coordenadas.insert(2*i, Clases::Coordenada.new(x0+k*w,y0+n*h)) coordenadas.insert(2*i+1, Clases::Coordenada.new(xN-k*w,y0+n*h)) #NEXT k+=1 if k==nX then k=0 n+=1 end i+=1 end return coordenadas end |
.imponerBooklet(impostor, temp) ⇒ Object
TODO 1 sola vez pdflatex?
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 |
# File 'lib/imposition/metodos.rb', line 208 def self.imponerBooklet(impostor,temp) #unidades latex wC=pdflatexUnit(impostor.w_["numero"], impostor.w_["unidad"]) impostor.w=wC[0] impostor.w_["unidad"]=wC[1] hC=pdflatexUnit(impostor.h_["numero"], impostor.h_["unidad"]) impostor.h=hC[0] impostor.h_["unidad"]=hC[1] wDummy=impostor.w_["numero"].to_f#bug alchemist pierpa=File.dirname(temp)+"/"+"booKlet.tex" File.open(pierpa, 'w') do |booklet| booklet.puts "\\documentclass{report}" booklet.puts "\\usepackage{pdfpages}" booklet.puts "\\usepackage{geometry}" booklet.puts "\\geometry{" booklet.puts "papersize={#{impostor.w_["numero"]}#{impostor.h_["unidad"]},#{impostor.h_["numero"]}#{impostor.h_["unidad"]}}," booklet.puts "left=0mm,"#posibilidad de márgenes booklet.puts "right=0mm," booklet.puts "top=0mm," booklet.puts "bottom=0mm," booklet.puts "ignoreall," booklet.puts "headsep=0mm," booklet.puts "headheight=0mm," booklet.puts "foot=0mm," booklet.puts "marginpar=0mm" booklet.puts "}" booklet.puts "\\begin{document}" booklet.puts "\\includepdf[pages={#{impostor.bookletz.join(",")}},nup=2x1,noautoscale,width=#{wDummy/2}#{impostor.w_["unidad"]}, height=#{impostor.h_["numero"]}#{impostor.h_["unidad"]}]{#{temp}}" booklet.puts "\\end{document}" end #LaTeX Dir.chdir(File.dirname(temp)) tIni=Time.now pdflatex=`#{$requerimientos["pdflatex"]} #{pierpa}` tFin=Time.now t=tFin-tIni Dir.chdir($codeDir) #lo devuelvo FileUtils.mv(File.dirname(temp)+"/"+"booKlet.pdf", temp) #retorno return Clases::MensajeTiempo.new(1,t) end |
.imponerStack(impostor, temp) ⇒ Object
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 |
# File 'lib/imposition/metodos.rb', line 148 def self.imponerStack(impostor,temp) wPC=pdflatexUnit(impostor.wP, impostor.wP_["unidad"]) impostor.wP=wPC[0] impostor.wP_["unidad"]=wPC[1] hPC=pdflatexUnit(impostor.hP, impostor.hP_["unidad"]) impostor.hP=hPC[0] impostor.hP_["unidad"]=hPC[1] wC=pdflatexUnit(impostor.w, impostor.w_["unidad"]) impostor.w=wC[0] impostor.w_["unidad"]=wC[1] hC=pdflatexUnit(impostor.h, impostor.h_["unidad"]) impostor.h=hC[0] impostor.h_["unidad"]=hC[1] #las paginas que no existen se dejan en blanco cS=cutStack(impostor.nX,impostor.nY,impostor.nPaginas,impostor.nPliegos,impostor.w.to_f,impostor.h.to_f) for i in 0...cS.size if cS[i].to_i > impostor.nPaginasReal then cS[i]="{}" end end cS=cS.join(",") cutted=File.dirname(temp)+"/"+"cutStack.tex" File.open(cutted, 'w') do |cutStack| cutStack.puts "\\documentclass{report}" cutStack.puts "\\usepackage{pdfpages}" cutStack.puts "\\usepackage{geometry}" cutStack.puts "\\geometry{" cutStack.puts "papersize={#{impostor.wP}#{impostor.wP_["unidad"]},#{impostor.hP}#{impostor.hP_["unidad"]}}," cutStack.puts "left=0mm,"#posibilidad de márgenes cutStack.puts "right=0mm," cutStack.puts "top=0mm," cutStack.puts "bottom=0mm," cutStack.puts "ignoreall," cutStack.puts "headsep=0mm," cutStack.puts "headheight=0mm," cutStack.puts "foot=0mm," cutStack.puts "marginpar=0mm" cutStack.puts "}" cutStack.puts "\\begin{document}" cutStack.puts "\\includepdf[pages={#{cS}},nup=#{impostor.nX}x#{impostor.nY},noautoscale, width=#{impostor.w}#{impostor.w_["unidad"]}, height=#{impostor.h}#{impostor.h_["unidad"]}]{#{temp}}" #TODO frame opcional cutStack.puts "\\end{document}" end #LaTeX Dir.chdir(File.dirname(temp)) tIni=Time.now pdflatex=`#{$requerimientos["pdflatex"]} #{cutted}` tFin=Time.now t=tFin-tIni Dir.chdir($codeDir) #retorno return Clases::MensajeTiempo.new(2,t) end |
.input2alchemist(unidad) ⇒ Object
TODO validar que unidad exista en alchemist
75 76 77 78 79 80 81 82 83 |
# File 'lib/imposition/metodos.rb', line 75 def input2alchemist(unidad) if unidad=="pt" or unidad=="pts" then return "point" elsif unidad=="PT" or unidad=="bp" then return "printer_point" else return unidad.downcase end end |
.mult4(paginasEnPliego) ⇒ Object
multiplo de 4
411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/imposition/metodos.rb', line 411 def self.mult4(paginasEnPliego) msg=nil paginas=paginasEnPliego if paginasEnPliego%4 != 0 then paginas=((paginasEnPliego/4)+1)*4 msg=Clases::Mensaje.new(1,"se necesitaran #{paginas}p para imponer #{paginasEnPliego}p en #{paginas/4} cuadernillos plegables") else paginas=paginasEnPliego end return [paginas,msg] end |
.myPlacePDF(nX, nY, nPaginas, nPliegos) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/imposition/metodos.rb', line 252 def self.myPlacePDF(nX,nY,nPaginas,nPliegos) myCounter=1 #numero de pagina myPosition=0 #posicion en las coordenadas @Transfer=0 #pliego arreglo=[] while (myCounter!=nPaginas+1) do #USO pos=Clases::Posicion.new(myCounter, myPosition, @Transfer) arreglo.push(pos) #NEXT @Transfer+=1 if myCounter%2==0 then myPosition-=2 end myPosition+=1 if @Transfer==nPliegos then @Transfer=0 myPosition+=2 end myCounter+=1 end return arreglo end |
.nuevo(valor, unidad) ⇒ Object
forma hash de variable para impostor
95 96 97 98 99 100 |
# File 'lib/imposition/metodos.rb', line 95 def nuevo(valor,unidad) retorno=Hash.new retorno["numero"]=valor ||= 0 retorno["unidad"]=unidad return retorno end |
.ordenar(mix) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/imposition/metodos.rb', line 303 def self.ordenar(mix) for j in 0...mix.length for k in 0...mix.length if mix[j].t>mix[k].t and j<k then #si es de un pliego mayor temp=mix[j] mix[j]=mix[k] mix[k]=temp elsif mix[j].t==mix[k].t then #si es del mismo pliego if mix[j].y>mix[k].y and j<k then#si es de una fila mayor temp=mix[j] mix[j]=mix[k] mix[k]=temp elsif mix[j].y==mix[k].y then #si es de la misma if mix[j].x>mix[k].x and j<k then #si esta despues temp=mix[j] mix[j]=mix[k] mix[k]=temp end end end end end return mix end |
.pagesize(pdfinfo) ⇒ Object
tamaño de página
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/imposition/metodos.rb', line 124 def self.pagesize(pdfinfo) info = pdfinfo.chomp busca = /Page size\s*\:\s*([\d\.]+)\s*x\s*([\d\.]+).*/ pags = busca.match(info) retorno=Hash.new splitted=pags[0].split(" ") unidad=splitted[5] #unidades pdfinfo 2 alchemist if unidad=="pts" then unidad="point" #TODO elsif... else#default unidad="point" end retorno["unidad"]=unidad #con unidad retorno["ancho"]=pags[1].to_f.send(unidad) retorno["alto"]=pags[2].to_f.send(unidad) if splitted[6]!=nil then retorno["nombre"]=splitted[6].delete("(").delete(")") end return retorno end |
.paginasdelpdf(pdfinfo) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/imposition/metodos.rb', line 115 def self.paginasdelpdf(pdfinfo) info = pdfinfo.chomp busca = /pages\s*\:\s*(\d+)/moi pags = busca.match(info) paginas = pags[1] return paginas.to_i end |
.pdfinfo(impostor, temp) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/imposition/metodos.rb', line 105 def self.pdfinfo(impostor, temp) Dir.chdir(File.dirname(temp)) pdfinfo = `#{$requerimientos["pdfinfo"]} -box #{temp}` impostor.nPaginasReal=paginasdelpdf(pdfinfo) impostor.size=Metodos.pagesize(pdfinfo) impostor.wReal=impostor.size["ancho"] impostor.hReal=impostor.size["alto"] Dir.chdir($codeDir) end |
.pdflatexUnit(x, unidad) ⇒ Object
conversion unidades alchemy 2 pdflatex
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/imposition/metodos.rb', line 346 def self.pdflatexUnit(x, unidad) if unidad=="point" then return [x,"pt"] elsif unidad=="printer_point" then return [x,"bp"] elsif unidad=="m" then x=x.to.cm return [x,"cm"] elsif unidad=="inch" then return [x, "in"] #TODO elsif... else return [x,unidad] end end |
.redondear(n) ⇒ Object
por BUG de alchemist (ruby 1.9 tiene round(3))
386 387 388 |
# File 'lib/imposition/metodos.rb', line 386 def self.redondear(n)#por BUG de alchemist (ruby 1.9 tiene round(3)) (n*1000).round/1000 end |
.refresh ⇒ Object
permite globales porque se encapsula logica de test y ejecutable
86 87 88 89 90 91 92 |
# File 'lib/imposition/metodos.rb', line 86 def refresh dir=$work+"/"+UUIDTools::UUID.random_create Dir.mkdir(dir) $codeDir = Dir.pwd $temp=dir+"/"+File.basename($entrada)#me lo llevo FileUtils.cp($entrada, $temp) end |
.unaDentroDeOtra(paginasReal, paginasEnCuadernillo, inicio, fin) ⇒ Object
crea un cuadernillo
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/imposition/metodos.rb', line 363 def self.unaDentroDeOtra(paginasReal, paginasEnCuadernillo, inicio, fin) #llegan como float inicio=inicio.to_i fin=fin.to_i arreglo=[] for i in 0...paginasEnCuadernillo/2 if (i+1)%2!=0 then arreglo.push(fin-i) arreglo.push(i+inicio) else arreglo.push(i+inicio) arreglo.push(fin-i) end end for i in 0...arreglo.length #TODO vale la pena meterlo en el loop anterior o de todos modos el de cut&Stack la hace y lo elimino? if arreglo[i]>paginasReal then arreglo[i]="{}" end end return arreglo end |
.validacion(impostor, preguntas) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/imposition/metodos.rb', line 437 def self.validacion(impostor, preguntas) mensajes=[] if preguntas==nil then preguntas=Hash.new end if impostor.cuadernillos then if impostor.nX%2!=0 then if preguntas["par"]==nil or !preguntas["par"].ok then preguntas["par"]=Clases::PreguntaExigePar.new(impostor.nX) return Clases::RespuestaImpostor.new(preguntas,mensajes) else impostor.nX=preguntas["par"].nX end end if preguntas["cXC"]==nil or !preguntas["cXC"].ok then preguntas["cXC"]=Clases::PreguntaCXC.new() return Clases::RespuestaImpostor.new(preguntas,mensajes) else impostor.cuadernillosPorCostura=preguntas["cXC"].cXC end impostor.nX=impostor.nX/2 impostor.w=impostor.w*2 impostor.w_["numero"]=impostor.w mensajes.push(Clases::MensajeBooklets.new(1, "como imponemos en cuadernillos, tomamos la mitad de paginas horizontalmente y una pagina del doble de ancho")) end #HORIZONTALMENTE if impostor.w!=0.point then if impostor.wP!=0.point then if impostor.nX==0 then impostor.nX=(wP/w).floor impostor.wP=impostor.wP_["numero"].send(impostor.wP_["unidad"])#operación alchemist cambia el operando if impostor.nX==0 then mensajes.push(Clases::MensajeDato.new(3, "horizontal", 5))#error else mensajes.push(Clases::MensajeDato.new(1, "horizontal", 1))#info end end elsif impostor.nX!=0 then if impostor.wP==0.point then impostor.wP_["numero"]=impostor.nX*impostor.w.to_f#actualiza para no perderlo en operacion de medidas impostor.wP=impostor.wP_["numero"].send(impostor.w_["unidad"]) impostor.wP_["unidad"]=impostor.w_["unidad"] mensajes.push(Clases::MensajeDato.new(1, "horizontal", 2))#info end else mensajes.push(Clases::MensajeDato.new(3, "horizontal", 1))#error end elsif impostor.wP!=0.point then if impostor.nX!=0 then if preguntas["escaladoH"]==nil or !preguntas["escaladoH"].ok then preguntas["escaladoH"]=Clases::PreguntaEscalado.new("horizontalmente") else if preguntas["escaladoH"].yn then impostor.w=(impostor.wP.to_f/(impostor.nX*(impostor.cuadernillos ? 2 : 1))).send(impostor.wP_["unidad"])#divido en 2 porque ya lo multipliqué impostor.w_["numero"]=impostor.w impostor.w_["unidad"]=impostor.wP_["unidad"] mensajes.push(Clases::MensajeDato.new(1, "horizontal", 3))#info else impostor.w=impostor.wReal if impostor.cuadernillos then impostor.w=impostor.w*2 impostor.w_["numero"]=impostor.w end impostor.w_["unidad"]=impostor.size["unidad"] mensajes.push(Clases::MensajeDato.new(1, "horizontal", 4))#info end end else impostor.w=impostor.wReal if impostor.cuadernillos then impostor.w=impostor.w*2 impostor.w_["numero"]=impostor.w puts impostor.w end impostor.w_["unidad"]=impostor.size["unidad"] mensajes.push(Clases::MensajeDato.new(1, "horizontal", 4))#info impostor.nX=(impostor.wP/impostor.w).floor impostor.wP=impostor.wP_["numero"].send(impostor.wP_["unidad"]) if impostor.nX==0 then mensajes.push(Clases::MensajeDato.new(3, "horizontal", 5))#error else mensajes.push(Clases::MensajeDato.new(1, "horizontal", 1))#info end end elsif impostor.nX!=0 then impostor.w=impostor.wReal if impostor.cuadernillos then impostor.w=impostor.w*2 end impostor.w_["numero"]=impostor.w impostor.w_["unidad"]=impostor.size["unidad"] mensajes.push(Clases::MensajeDato.new(1, "horizontal", 4))#info impostor.wP_["numero"]=impostor.nX*impostor.w.to_f impostor.wP=impostor.wP_["numero"].send(impostor.w_["unidad"]) impostor.wP_["unidad"]=impostor.w_["unidad"] mensajes.push(Clases::MensajeDato.new(1, "horizontal", 2))#info else mensajes.push(Clases::MensajeDato.new(3, "horizontal", 4))#error end #VERTICALMENTE if impostor.h!=0.point then if impostor.hP!=0.point then if impostor.nY==0 then impostor.nY=(impostor.hP/impostor.h).floor impostor.hP=impostor.hP_["numero"].send(impostor.hP_["unidad"]) if impostor.nY==0 then mensajes.push(Clases::MensajeDato.new(3, "vertical", 5))#error else mensajes.push(Clases::MensajeDato.new(1, "vertical", 1))#info end end elsif impostor.nY!=0 then if impostor.hP==0.point then impostor.hP_["numero"]=impostor.nY*impostor.h.to_f impostor.hP=impostor.hP_["numero"].send(impostor.h_["unidad"]) impostor.hP_["unidad"]=impostor.h_["unidad"] mensajes.push(Clases::MensajeDato.new(1, "vertical", 2))#info end else mensajes.push(Clases::MensajeDato.new(3, "vertical", 1))#error end elsif impostor.hP!=0.point then if impostor.nY!=0 then if preguntas["escaladoV"]==nil or !preguntas["escaladoV"].ok then preguntas["escaladoV"]=Clases::PreguntaEscalado.new("verticalmente") else if preguntas["escaladoV"].yn then impostor.h=(impostor.hP.to_f/impostor.nY).send(impostor.hP_["unidad"]) impostor.h_["numero"]=impostor.h impostor.h_["unidad"]=impostor.hP_["unidad"] mensajes.push(Clases::MensajeDato.new(1, "vertical", 3))#info else impostor.h=impostor.hReal impostor.h_["numero"]=impostor.h impostor.h_["unidad"]=impostor.size["unidad"] mensajes.push(Clases::MensajeDato.new(1, "vertical", 4))#info end end else #deducimos del pdf no mas impostor.h=impostor.hReal impostor.h_["numero"]=impostor.h impostor.h_["unidad"]=impostor.size["unidad"] mensajes.push(Clases::MensajeDato.new(1, "vertical", 4))#info impostor.nY=(impostor.hP/impostor.h).floor impostor.hP=impostor.hP_["numero"].send(impostor.hP_["unidad"]) if impostor.nY==0 then mensajes.push(Clases::MensajeDato.new(3, "vertical", 5))#error else mensajes.push(Clases::MensajeDato.new(1, "vertical", 1))#info end end elsif impostor.nY!=0 then impostor.h=impostor.hReal impostor.h_["numero"]=impostor.h impostor.h_["unidad"]=impostor.size["unidad"] mensajes.push(Clases::MensajeDato.new(1, "vertical", 4))#info impostor.hP_["numero"]=impostor.nY*impostor.h.to_f impostor.hP=impostor.hP_["numero"].send(impostor.h_["unidad"]) impostor.hP_["unidad"]=impostor.h_["unidad"] mensajes.push(Clases::MensajeDato.new(1, "vertical", 2))#info else mensajes.push(Clases::MensajeDato.new(3, "vertical", 4))#error end #MEDIDAS wPDummy=impostor.wP_["numero"].send(impostor.wP_["unidad"])#bug alchemist hPDummy=impostor.hP_["numero"].send(impostor.hP_["unidad"]) if redondear(impostor.nX*impostor.w.to_f) > redondear(impostor.wP.to(impostor.w_["unidad"]).to_f) then mensajes.push(Clases::MensajeMedida.new(3, "horizontal", [impostor.nX, impostor.w_, impostor.wP_]))#error elsif impostor.nX>0 and wPDummy -(impostor.nX*impostor.w.to_f).send(impostor.w_["unidad"]) > 1.send("point") then sobra=impostor.wP-(impostor.nX*impostor.w.to_f).send(impostor.w_["unidad"]) impostor.wP=impostor.wP_["numero"].send(impostor.wP_["unidad"]) mensajes.push(Clases::MensajeMedida.new(2, "horizontal", [sobra, impostor.wP_["unidad"]]))#warn end if redondear(impostor.nY*impostor.h.to_f) > redondear(impostor.hP.to(impostor.h_["unidad"]).to_f) then mensajes.push(Clases::MensajeMedida.new(3, "vertical", [impostor.nY, impostor.h_, impostor.hP_]))#error elsif impostor.nY>0 and hPDummy - (impostor.nY*impostor.h.to_f).send(impostor.h_["unidad"]) > 1.send("point") then sobra=impostor.hP-(impostor.nY*impostor.h.to_f).send(impostor.h_["unidad"]) impostor.hP=impostor.hP_["numero"].send(impostor.hP_["unidad"]) mensajes.push(Clases::MensajeMedida.new(2, "vertical", [sobra, impostor.hP_["unidad"]]))#warn end #PAGINAS nXm=impostor.nX if impostor.cuadernillos then nXm*=2 end if impostor.nPaginas==0 then if impostor.nPliegos!=0 then nCaben=impostor.nPliegos*nXm*impostor.nY if preguntas["todasPag"]==nil or !preguntas["todasPag"].ok then preguntas["todasPag"]=Clases::PreguntaTodasPag.new(impostor.nPliegos, nXm, impostor.nY, nCaben, impostor.nPaginasReal) else if !preguntas["todasPag"].yn then impostor.nPaginas=nCaben if nCaben <= impostor.nPaginas then mensajes.push(Clases::MensajeDato.new(1, "paginas", 1))#info else mensajes.push(Clases::MensajeDato.new(3, "paginas", 1))#error end else impostor.nPaginas=impostor.nPaginasReal mensajes.push(Clases::MensajeDato.new(1, "paginas", 3))#info end end else impostor.nPaginas=impostor.nPaginasReal mensajes.push(Clases::MensajeDato.new(1, "paginas", 3))#info end else if impostor.nPaginas < impostor.nPaginasReal then impostor.nPaginasReal=impostor.nPaginas end end #no se cuantos pliegos if impostor.nX!=0 and impostor.nY!=0 then nPliegosCalc=(impostor.nPaginas.to_f/(nXm*impostor.nY)).ceil if impostor.nPliegos==0 then impostor.nPliegos=nPliegosCalc if impostor.nPliegos%2!=0 then mensajes.push(Clases::MensajeLadoLado.new(impostor.nPliegos)) impostor.nPliegos=(impostor.nPliegos.to_f/2).ceil*2 impostor.nPaginas=impostor.nPliegos*nXm*impostor.nY end mensajes.push(Clases::MensajeDato.new(1, "paginas", 2))#info else if impostor.nPliegos<nPliegosCalc then faltan=nPliegosCalc-impostor.nPliegos mensajes.push(Clases::MensajeDato.new(3, "pliegos", faltan))#error elsif impostor.nPliegos>nPliegosCalc then sobran=impostor.nPliegos-nPliegosCalc mensajes.push(Clases::MensajeDato.new(2, "pliegos", sobran))#warn end end end if impostor.cuadernillos then q=nil m4=mult4(impostor.nPaginas) impostor.nPaginas=m4.shift msg=m4.shift if msg!=nil then mensajes.push(msg) end if impostor.cuadernillosPorCostura==0 then pagsEnCuadernillo=impostor.nPaginas#todos unos dentro de otros else pagsEnCuadernillo=impostor.cuadernillosPorCostura*4 end if preguntas["reducir"]==nil or !preguntas["reducir"].ok then reducir=cortarCola(impostor.nPaginas, pagsEnCuadernillo, impostor.cuadernillosPorCostura) if reducir!=nil then preguntas["reducir"]=reducir end else if preguntas["reducir"].yn then q=preguntas["reducir"].q end end impostor.bookletz=booklets(pagsEnCuadernillo, impostor.nPaginas, impostor.nPaginasReal, q) impostor.nPaginas=impostor.bookletz.length/2 impostor.nPliegos=(2*impostor.nPaginas.to_f/(nXm*impostor.nY)).ceil #mensajes.push(Clases::MensajeDato.new(1, "paginas", 2))#info TODO if not already end #nPaginas multiplo de nX*nY if impostor.nX*impostor.nY!=0 and impostor.nPaginas%(impostor.nX*impostor.nY)!=0 then impostor.nPaginas=(impostor.nPaginas/(impostor.nX*impostor.nY)+1)*(impostor.nX*impostor.nY) mensajes.push(Clases::MensajeMultiplo.new(1, "El pdf tiene #{impostor.nPaginasReal} paginas, que impuestas en #{impostor.nX}x#{impostor.nY} son #{impostor.nPaginas} paginas")) #TODO impostor.nPliegos=(impostor.nPaginas.to_f/(nXm*impostor.nY)).ceil ? end return Clases::RespuestaImpostor.new(preguntas,mensajes) end |