1 2 17 18 package org.apache.poi.hwpf.sprm; 20 21 239 240 import java.util.ArrayList ; 241 import java.util.Arrays ; 242 243 import org.apache.poi.hwpf.model.types.SEPAbstractType; 244 import org.apache.poi.hwpf.usermodel.SectionProperties; 245 import org.apache.poi.util.LittleEndian; 246 247 248 public class SectionSprmCompressor 249 { 250 private final static SectionProperties DEFAULT_SEP = new SectionProperties(); 251 public SectionSprmCompressor() 252 { 253 } 254 public static byte[] compressSectionProperty(SectionProperties newSEP) 255 { 256 int size = 0; 257 ArrayList sprmList = new ArrayList (); 258 259 if (newSEP.getCnsPgn() != DEFAULT_SEP.getCnsPgn()) 260 { 261 size += SprmUtils.addSprm((short)0x3000, newSEP.getCnsPgn(), null, sprmList); 262 } 263 if (newSEP.getIHeadingPgn() != DEFAULT_SEP.getIHeadingPgn()) 264 { 265 size += SprmUtils.addSprm((short)0x3001, newSEP.getIHeadingPgn(), null, sprmList); 266 } 267 if (!Arrays.equals(newSEP.getOlstAnm(), DEFAULT_SEP.getOlstAnm())) 268 { 269 size += SprmUtils.addSprm((short)0xD202, 0, newSEP.getOlstAnm(), sprmList); 270 } 271 if (newSEP.getFEvenlySpaced() != DEFAULT_SEP.getFEvenlySpaced()) 272 { 273 size += SprmUtils.addSprm((short)0x3005, newSEP.getFEvenlySpaced() ? 1 : 0, null, sprmList); 274 } 275 if (newSEP.getFUnlocked() != DEFAULT_SEP.getFUnlocked()) 276 { 277 size += SprmUtils.addSprm((short)0x3006, newSEP.getFUnlocked() ? 1 :0, null, sprmList); 278 } 279 if (newSEP.getDmBinFirst() != DEFAULT_SEP.getDmBinFirst()) 280 { 281 size += SprmUtils.addSprm((short)0x5007, newSEP.getDmBinFirst(), null, sprmList); 282 } 283 if (newSEP.getDmBinOther() != DEFAULT_SEP.getDmBinOther()) 284 { 285 size += SprmUtils.addSprm((short)0x5008, newSEP.getDmBinOther(), null, sprmList); 286 } 287 if (newSEP.getBkc() != DEFAULT_SEP.getBkc()) 288 { 289 size += SprmUtils.addSprm((short)0x3009, newSEP.getBkc(), null, sprmList); 290 } 291 if (newSEP.getFTitlePage() != DEFAULT_SEP.getFTitlePage()) 292 { 293 size += SprmUtils.addSprm((short)0x300A, newSEP.getFTitlePage() ? 1 : 0, null, sprmList); 294 } 295 if (newSEP.getCcolM1() != DEFAULT_SEP.getCcolM1()) 296 { 297 size += SprmUtils.addSprm((short)0x500B, newSEP.getCcolM1(), null, sprmList); 298 } 299 if (newSEP.getDxaColumns() != DEFAULT_SEP.getDxaColumns()) 300 { 301 size += SprmUtils.addSprm((short)0x900C, newSEP.getDxaColumns(), null, sprmList); 302 } 303 if (newSEP.getFAutoPgn() != DEFAULT_SEP.getFAutoPgn()) 304 { 305 size += SprmUtils.addSprm((short)0x300D, newSEP.getFAutoPgn() ? 1 : 0, null, sprmList); 306 } 307 if (newSEP.getNfcPgn() != DEFAULT_SEP.getNfcPgn()) 308 { 309 size += SprmUtils.addSprm((short)0x300E, newSEP.getNfcPgn(), null, sprmList); 310 } 311 if (newSEP.getDyaPgn() != DEFAULT_SEP.getDyaPgn()) 312 { 313 size += SprmUtils.addSprm((short)0xB00F, newSEP.getDyaPgn(), null, sprmList); 314 } 315 if (newSEP.getDxaPgn() != DEFAULT_SEP.getDxaPgn()) 316 { 317 size += SprmUtils.addSprm((short)0xB010, newSEP.getDxaPgn(), null, sprmList); 318 } 319 if (newSEP.getFPgnRestart() != DEFAULT_SEP.getFPgnRestart()) 320 { 321 size += SprmUtils.addSprm((short)0x3011, newSEP.getFPgnRestart() ? 1 : 0, null, sprmList); 322 } 323 if (newSEP.getFEndNote() != DEFAULT_SEP.getFEndNote()) 324 { 325 size += SprmUtils.addSprm((short)0x3012, newSEP.getFEndNote() ? 1 : 0, null, sprmList); 326 } 327 if (newSEP.getLnc() != DEFAULT_SEP.getLnc()) 328 { 329 size += SprmUtils.addSprm((short)0x3013, newSEP.getLnc(), null, sprmList); 330 } 331 if (newSEP.getGrpfIhdt() != DEFAULT_SEP.getGrpfIhdt()) 332 { 333 size += SprmUtils.addSprm((short)0x3014, newSEP.getGrpfIhdt(), null, sprmList); 334 } 335 if (newSEP.getNLnnMod() != DEFAULT_SEP.getNLnnMod()) 336 { 337 size += SprmUtils.addSprm((short)0x5015, newSEP.getNLnnMod(), null, sprmList); 338 } 339 if (newSEP.getDxaLnn() != DEFAULT_SEP.getDxaLnn()) 340 { 341 size += SprmUtils.addSprm((short)0x9016, newSEP.getDxaLnn(), null, sprmList); 342 } 343 if (newSEP.getDyaHdrTop() != DEFAULT_SEP.getDyaHdrTop()) 344 { 345 size += SprmUtils.addSprm((short)0xB017, newSEP.getDyaHdrTop(), null, sprmList); 346 } 347 if (newSEP.getDyaHdrBottom() != DEFAULT_SEP.getDyaHdrBottom()) 348 { 349 size += SprmUtils.addSprm((short)0xB018, newSEP.getDyaHdrBottom(), null, sprmList); 350 } 351 if (newSEP.getFLBetween() != DEFAULT_SEP.getFLBetween()) 352 { 353 size += SprmUtils.addSprm((short)0x3019, newSEP.getFLBetween() ? 1 : 0, null, sprmList); 354 } 355 if (newSEP.getVjc() != DEFAULT_SEP.getVjc()) 356 { 357 size += SprmUtils.addSprm((short)0x301A, newSEP.getVjc(), null, sprmList); 358 } 359 if (newSEP.getLnnMin() != DEFAULT_SEP.getLnnMin()) 360 { 361 size += SprmUtils.addSprm((short)0x501B, newSEP.getLnnMin(), null, sprmList); 362 } 363 if (newSEP.getPgnStart() != DEFAULT_SEP.getPgnStart()) 364 { 365 size += SprmUtils.addSprm((short)0x501C, newSEP.getPgnStart(), null, sprmList); 366 } 367 if (newSEP.getDmOrientPage() != DEFAULT_SEP.getDmOrientPage()) 368 { 369 size += SprmUtils.addSprm((short)0x301D, newSEP.getDmOrientPage(), null, sprmList); 370 } 371 if (newSEP.getXaPage() != DEFAULT_SEP.getXaPage()) 372 { 373 size += SprmUtils.addSprm((short)0xB01F, newSEP.getXaPage(), null, sprmList); 374 } 375 if (newSEP.getYaPage() != DEFAULT_SEP.getYaPage()) 376 { 377 size += SprmUtils.addSprm((short)0xB020, newSEP.getYaPage(), null, sprmList); 378 } 379 if (newSEP.getDxaLeft() != DEFAULT_SEP.getDxaLeft()) 380 { 381 size += SprmUtils.addSprm((short)0xB021, newSEP.getDxaLeft(), null, sprmList); 382 } 383 if (newSEP.getDxaRight() != DEFAULT_SEP.getDxaRight()) 384 { 385 size += SprmUtils.addSprm((short)0xB022, newSEP.getDxaRight(), null, sprmList); 386 } 387 if (newSEP.getDyaTop() != DEFAULT_SEP.getDyaTop()) 388 { 389 size += SprmUtils.addSprm((short)0x9023, newSEP.getDyaTop(), null, sprmList); 390 } 391 if (newSEP.getDyaBottom() != DEFAULT_SEP.getDyaBottom()) 392 { 393 size += SprmUtils.addSprm((short)0x9024, newSEP.getDyaBottom(), null, sprmList); 394 } 395 if (newSEP.getDzaGutter() != DEFAULT_SEP.getDzaGutter()) 396 { 397 size += SprmUtils.addSprm((short)0xB025, newSEP.getDzaGutter(), null, sprmList); 398 } 399 if (newSEP.getDmPaperReq() != DEFAULT_SEP.getDmPaperReq()) 400 { 401 size += SprmUtils.addSprm((short)0x5026, newSEP.getDmPaperReq(), null, sprmList); 402 } 403 if (newSEP.getFPropMark() != DEFAULT_SEP.getFPropMark() || 404 newSEP.getIbstPropRMark() != DEFAULT_SEP.getIbstPropRMark() || 405 !newSEP.getDttmPropRMark().equals(DEFAULT_SEP.getDttmPropRMark())) 406 { 407 byte[] buf = new byte[7]; 408 buf[0] = (byte)(newSEP.getFPropMark() ? 1 : 0); 409 int offset = LittleEndian.BYTE_SIZE; 410 LittleEndian.putShort(buf, (short)newSEP.getIbstPropRMark()); 411 offset += LittleEndian.SHORT_SIZE; 412 newSEP.getDttmPropRMark().serialize(buf, offset); 413 size += SprmUtils.addSprm((short)0xD227, -1, buf, sprmList); 414 } 415 if (!newSEP.getBrcTop().equals( DEFAULT_SEP.getBrcTop())) 416 { 417 size += SprmUtils.addSprm((short)0x702B, newSEP.getBrcTop().toInt(), null, sprmList); 418 } 419 if (!newSEP.getBrcLeft().equals(DEFAULT_SEP.getBrcLeft())) 420 { 421 size += SprmUtils.addSprm((short)0x702C, newSEP.getBrcLeft().toInt(), null, sprmList); 422 } 423 if (!newSEP.getBrcBottom().equals(DEFAULT_SEP.getBrcBottom())) 424 { 425 size += SprmUtils.addSprm((short)0x702D, newSEP.getBrcBottom().toInt(), null, sprmList); 426 } 427 if (!newSEP.getBrcRight().equals(DEFAULT_SEP.getBrcRight())) 428 { 429 size += SprmUtils.addSprm((short)0x702E, newSEP.getBrcRight().toInt(), null, sprmList); 430 } 431 if (newSEP.getPgbProp() != DEFAULT_SEP.getPgbProp()) 432 { 433 size += SprmUtils.addSprm((short)0x522F, newSEP.getPgbProp(), null, sprmList); 434 } 435 if (newSEP.getDxtCharSpace() != DEFAULT_SEP.getDxtCharSpace()) 436 { 437 size += SprmUtils.addSprm((short)0x7030, newSEP.getDxtCharSpace(), null, sprmList); 438 } 439 if (newSEP.getDyaLinePitch() != DEFAULT_SEP.getDyaLinePitch()) 440 { 441 size += SprmUtils.addSprm((short)0x9031, newSEP.getDyaLinePitch(), null, sprmList); 442 } 443 if (newSEP.getClm() != DEFAULT_SEP.getClm()) 444 { 445 size += SprmUtils.addSprm((short)0x5032, newSEP.getClm(), null, sprmList); 446 } 447 if (newSEP.getWTextFlow() != DEFAULT_SEP.getWTextFlow()) 448 { 449 size += SprmUtils.addSprm((short)0x5033, newSEP.getWTextFlow(), null, sprmList); 450 } 451 452 return SprmUtils.getGrpprl(sprmList, size); 453 } 454 } 455 456 | Popular Tags |