public override Status Layout(Area area) { if (!(area is BlockArea)) { FonetDriver.ActiveDriver.FireFonetWarning( "Page-number-citation outside block area"); return(new Status(Status.OK)); } IDReferences idReferences = area.getIDReferences(); this.area = area; if (this.marker == MarkerStart) { AccessibilityProps mAccProps = propMgr.GetAccessibilityProps(); AuralProps mAurProps = propMgr.GetAuralProps(); BorderAndPadding bap = propMgr.GetBorderAndPadding(); BackgroundProps bProps = propMgr.GetBackgroundProps(); MarginInlineProps mProps = propMgr.GetMarginInlineProps(); RelativePositionProps mRelProps = propMgr.GetRelativePositionProps(); ColorType c = this.properties.GetProperty("color").GetColorType(); this.red = c.Red; this.green = c.Green; this.blue = c.Blue; this.wrapOption = this.properties.GetProperty("wrap-option").GetEnum(); this.whiteSpaceCollapse = this.properties.GetProperty("white-space-collapse").GetEnum(); this.refId = this.properties.GetProperty("ref-id").GetString(); if (this.refId.Equals("")) { throw new FonetException("page-number-citation must contain \"ref-id\""); } this.id = this.properties.GetProperty("id").GetString(); idReferences.CreateID(id); ts = new TextState(); this.marker = 0; } if (marker == 0) { idReferences.ConfigureID(id, area); } pageNumber = idReferences.getPageNumber(refId); if (pageNumber != null) { this.marker = FOText.addText((BlockArea)area, propMgr.GetFontState(area.getFontInfo()), red, green, blue, wrapOption, null, whiteSpaceCollapse, pageNumber.ToCharArray(), 0, pageNumber.Length, ts, VerticalAlign.BASELINE); } else { BlockArea blockArea = (BlockArea)area; LineArea la = blockArea.getCurrentLineArea(); if (la == null) { return(new Status(Status.AREA_FULL_NONE)); } la.changeFont(propMgr.GetFontState(area.getFontInfo())); la.changeColor(red, green, blue); la.changeWrapOption(wrapOption); la.changeWhiteSpaceCollapse(whiteSpaceCollapse); la.addPageNumberCitation(refId, null); this.marker = -1; } if (this.marker == -1) { return(new Status(Status.OK)); } else { return(new Status(Status.AREA_FULL_NONE)); } }
/** * render inline area to PDF * * @param area inline area to render */ public void RenderWordArea(WordArea area) { FontState fontState = area.GetFontState(); String name = fontState.FontName; int size = fontState.FontSize; // This assumes that *all* CIDFonts use a /ToUnicode mapping Font font = (Font)fontState.FontInfo.GetFontByName(name); if ((!name.Equals(this.currentFontName)) || (size != this.currentFontSize)) { CloseText(); this.currentFontName = name; this.currentFontSize = size; currentStream.SetFont(name, size); } // Do letter spacing (must be outside of [...] TJ] float letterspacing = ((float)fontState.LetterSpacing) / 1000f; if (letterspacing != this.currentLetterSpacing) { this.currentLetterSpacing = letterspacing; CloseText(); //? currentStream.SetLetterSpacing(letterspacing); } //-------------------------------------------- PdfColor?a_color = this.currentFill; PdfColor areaObj_color = area.GetColor(); if (a_color == null || !areaObj_color.IsEq(a_color.Value)) { //change area color a_color = areaObj_color; CloseText(); //? this.currentFill = a_color; currentStream.SetFontColor(a_color.Value); } //-------------------------------------------- int rx = this.currentXPosition; int bl = this.currentYPosition; int areaContentW = area.getContentWidth(); if (area.getUnderlined()) { AddUnderLine(rx, bl, areaContentW, size, a_color.Value); } if (area.getOverlined()) { AddOverLine(rx, bl, areaContentW, size, fontState.Ascender, a_color.Value); } if (area.getLineThrough()) { AddLineThrough(rx, bl, areaContentW, size, fontState.Ascender, a_color.Value); } //-------------------------------------------- _textPrinter.Reset(fontState, options != null && options.Kerning); if (!textOpen || bl != prevWordY) { CloseText(); //set text matrix _textPrinter.SetTextPos(rx, bl); //pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) + // " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText); prevWordY = bl; textOpen = true; //*** } else { // express the space between words in thousandths of an em int space = prevWordX - rx + prevWordWidth; float emDiff = (float)space / (float)currentFontSize * 1000f; // this prevents a problem in Acrobat Reader where large // numbers cause text to disappear or default to a limit if (emDiff < -33000) { CloseText(); _textPrinter.SetTextPos(rx, bl); //pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) + // " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText); textOpen = true;//*** } else { _textPrinter.SetEmDiff(emDiff); //pdf.Append(PdfNumber.doubleOut(emDiff)); //pdf.Append(" "); //pdf.Append(startText); } } prevWordWidth = areaContentW; prevWordX = rx; string s = area.GetTextContent(); if (area is PageNumberInlineArea) { //need to resolve to page number s = idReferences.getPageNumber(s); } _textPrinter.WriteText(s); //------- _textPrinter.PrintContentTo(currentStream); //------- this.currentXPosition += area.getContentWidth(); }
/** * render inline area to PDF * * @param area inline area to render */ public void RenderWordArea(WordArea area) { // TODO: I don't understand why we are locking the private member // _wordAreaPDF. Maybe this string buffer was originally static? (MG) lock (_wordAreaPDF) { StringBuilder pdf = _wordAreaPDF; pdf.Length = 0; GdiKerningPairs kerning = null; bool kerningAvailable = false; // If no options are supplied, by default we do not enable kerning if (options != null && options.Kerning) { kerning = area.GetFontState().Kerning; if (kerning != null && (kerning.Count > 0)) { kerningAvailable = true; } } String name = area.GetFontState().FontName; int size = area.GetFontState().FontSize; // This assumes that *all* CIDFonts use a /ToUnicode mapping Font font = (Font)area.GetFontState().FontInfo.GetFontByName(name); bool useMultiByte = font.MultiByteFont; string startText = useMultiByte ? "<" : "("; string endText = useMultiByte ? "> " : ") "; if ((!name.Equals(this.currentFontName)) || (size != this.currentFontSize)) { CloseText(); this.currentFontName = name; this.currentFontSize = size; pdf = pdf.Append("/" + name + " " + PdfNumber.doubleOut(size / 1000f) + " Tf\n"); } // Do letter spacing (must be outside of [...] TJ] float letterspacing = ((float)area.GetFontState().LetterSpacing) / 1000f; if (letterspacing != this.currentLetterSpacing) { this.currentLetterSpacing = letterspacing; CloseText(); pdf.Append(PdfNumber.doubleOut(letterspacing)); pdf.Append(" Tc\n"); } PdfColor areaColor = this.currentFill; if (areaColor == null || areaColor.getRed() != (double)area.getRed() || areaColor.getGreen() != (double)area.getGreen() || areaColor.getBlue() != (double)area.getBlue()) { areaColor = new PdfColor((double)area.getRed(), (double)area.getGreen(), (double)area.getBlue()); CloseText(); this.currentFill = areaColor; pdf.Append(this.currentFill.getColorSpaceOut(true)); } int rx = this.currentXPosition; int bl = this.currentYPosition; AddWordLines(area, rx, bl, size, areaColor); if (!textOpen || bl != prevWordY) { CloseText(); pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) + " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText); prevWordY = bl; textOpen = true; } else { // express the space between words in thousandths of an em int space = prevWordX - rx + prevWordWidth; float emDiff = (float)space / (float)currentFontSize * 1000f; // this prevents a problem in Acrobat Reader where large // numbers cause text to disappear or default to a limit if (emDiff < -33000) { CloseText(); pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) + " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText); textOpen = true; } else { pdf.Append(PdfNumber.doubleOut(emDiff)); pdf.Append(" "); pdf.Append(startText); } } prevWordWidth = area.getContentWidth(); prevWordX = rx; string s; if (area.getPageNumberID() != null) { // This text is a page number, so resolve it s = idReferences.getPageNumber(area.getPageNumberID()); if (s == null) { s = String.Empty; } } else { s = area.getText(); } int wordLength = s.Length; for (int index = 0; index < wordLength; index++) { ushort ch = area.GetFontState().MapCharacter(s[index]); if (!useMultiByte) { if (ch > 127) { pdf.Append("\\"); pdf.Append(Convert.ToString((int)ch, 8)); } else { switch (ch) { case '(': case ')': case '\\': pdf.Append("\\"); break; } pdf.Append((char)ch); } } else { pdf.Append(GetUnicodeString(ch)); } if (kerningAvailable && (index + 1) < wordLength) { ushort ch2 = area.GetFontState().MapCharacter(s[index + 1]); AddKerning(pdf, ch, ch2, kerning, startText, endText); } } pdf.Append(endText); currentStream.Write(pdf.ToString()); this.currentXPosition += area.getContentWidth(); } }