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
//! Form 8275 (Disclosure Statement, Rev. 10-2024) fill: Part I disclosed positions (one row per T13
//! `Part1Item` — a promoted Form 8949 disposal leg's estimated basis) + Part II's filer-authored
//! narrative + the FILER's identity, read back through the shared SP2 flat oracle (`verify_flat`).
//!
//! **FREE-TEXT, not a money grid ([R0-C3] scope, T15).** Unlike `form8283.rs`'s property-table rows
//! (column-x-clustered `push_cell`), every Form 8275 write here is `push_free`
//! (`FlatPlacement::free`) — geometry-exempt but still page-checked, `/MaxLen`-checked, and inside the
//! no-unmapped set. Column (a) "Rev. Rul., Rev. Proc., etc." and column (e) "Line No." (a genuine
//! 3-character comb cell) are never written — see `Form8275Row`'s doc comment (`map.rs`) for why.
//!
//! **★ Year coverage is MANDATORY, not conditional (arch r1 I-6 / tax r1 M-7).** Form 8275 is
//! REVISION-versioned, not tax-year-versioned: `Form8275Map::for_year` and `pdf::f8275_pdf` both alias
//! the single bundled Rev. 10-2024 asset to EVERY `SUPPORTED_YEAR` (2017/2024/2025), so a promoted
//! disposal filed in any supported year gets a real fillable disclosure — this is what keeps T16's
//! re-pointed BG-D8 gate from PERMANENTLY refusing a promoted 2025 (or 2017) export, the dominant
//! current-year flow.
//!
//! **★ Part II is WRAPPED, never truncated (T-f8275-part-ii-overflow).** The filer's Part II narrative
//! is the §1.6662-4(f) adequate-disclosure text — the whole of Approach B's estimated-basis defense
//! rests on it. It used to be written whole to the ONE `part_ii_narrative` field, which is a
//! single-line, `DoNotScroll`, no-`/MaxLen` widget: the write always "succeeded" (nothing at the
//! PDF-data level stops an over-long `/V`), but a viewer honoring the widget's own box could only
//! DISPLAY the first ~137 characters at 8pt — a fifth of a disclosure is not a disclosure, and neither
//! `/MaxLen` (not declared on this field) nor `verify_flat`'s geometry leg (skipped for free
//! placements) could see it.
//!
//! **★ Only Part II's OWN line 1 (`part_ii_narrative`, `p1-t80[0]`) is ever written — round 2.** The
//! bundled PDF's XFA template draws printed numerals `"1 "`..`"6 "` beside `p1-t80[0]`..`p1-t85[0]`
//! (`Line1PartII`..`Line6PartII`, confirmed by decompressing the asset's own `template` XFA packet),
//! numbered to match Part I's 6 rows — Part II line *n* is meant to explain Part I row *n*. Spreading
//! one COMBINED narrative (multiple promoted tranches' accounts, joined by
//! `btctax-core/src/tax/form8275.rs`) across those numbered lines would attribute sentence fragments to
//! Part I items they do not explain — an early build of this fix did exactly that and its own golden
//! showed line 2's text sitting beside Part I's SECOND row while actually continuing line 1's sentence.
//! Per-item numbering (one explanation per numbered line, matched to its own Part I row) is the more
//! faithful long-term shape, but it is a bigger change (needs `Part1Item`-to-narrative correlation this
//! crate does not have today) — filed as a follow-up, not built here
//! (`design/f8275-part-ii-overflow/FOLLOWUPS.md`). For now: everything past Part II's line 1 spills to
//! Part IV instead, which has no per-line numbering to misclaim.
//!
//! **★ Part IV carries the IRS-required cross-reference.** Rev. 10-2024's Specific Instructions for
//! Part IV: *"Use Part IV on page 2 if you need more space for Parts I and/or II. Include the
//! corresponding part and line number from page 1."* Page 2 is captioned "Explanations (continued
//! from Parts I **and/or** II)" — an examiner reading it cold cannot tell which without the label. The
//! FIRST Part IV line used therefore always starts with
//! [`crate::wrap::PART_IV_CROSS_REFERENCE_PREFIX`] ("Part II, line 1 (continued): "), budgeted into the
//! wrap so it never itself causes an overflow.
//!
//! **★ The wrap budgets the renderer's text inset, not the raw widget box.** AcroForm variable text is
//! inset from its `/Rect` edges by (at minimum) border width + 1 (PDF 32000-1 §12.7.4.3); measured
//! against this asset, poppler starts ~2.16pt in from the left edge and pdf.js is more conservative
//! still (≈4pt total) — budgeting the RAW rect width let 3 lines of the fix's own >1500-char KAT
//! fixture measure over their box once inset was accounted for (see
//! `design/f8275-part-ii-overflow/BUILD-REPORT.md`). [`usable_width`] subtracts
//! `2 * TEXT_INSET_PTS` before `crate::wrap` ever sees a width.
//!
//! `crate::wrap` measures at the SAME Helvetica-Bold 8pt the PDF's own `/DA` declares (using the
//! bundled asset's OWN embedded font `/Widths`, not a generic AFM table — see `wrap.rs`'s doc comment)
//! and wraps the narrative, respecting paragraph breaks as hard breaks (`wrap::split_paragraphs`) so
//! two promoted tranches' independent accounts never blend into one filed sentence. If it still will
//! not fit across Part II's line 1 + all of Part IV, the fill fails closed with [`FormsError::Overflow`]
//! (mirroring the Part I >6-row refusal below) rather than clip. [`part_ii_capacity_check`] runs the
//! SAME wrap without filling anything, so `btctax-cli`'s export paths can refuse before writing any
//! packet file at all.
use crateFormsError;
use crateForm8275Map;
use crate;
use crate;
use crate::;
use ReturnHeader;
use Printed8275;
/// The font size Form 8275's Part II ("Detailed Explanation") and Part IV ("Explanations (continued
/// from Parts I and/or II)") continuation lines declare in their own `/DA`
/// (`/HelveticaLTStd-Bold 8.00 Tf`, verified against the bundled Rev. 10-2024 asset) — the size
/// `crate::wrap` measures the narrative at.
const PART_II_FONT_SIZE_PT: f32 = 8.0;
/// Minimum text inset (PDF points) a `/Rect`'s raw width is reduced by, PER SIDE, before it is treated
/// as usable — see the module doc's "the wrap budgets the renderer's text inset" note. `2.0` matches
/// pdf.js's observed ≈4pt total inset on this asset (the more conservative of the renderers measured),
/// while still comfortably covering poppler's smaller ~2.16pt.
const TEXT_INSET_PTS: f32 = 2.0;
/// The usable text width of field `fqn` (its `/Rect` width minus `2 * TEXT_INSET_PTS`) — the SAME
/// figure both the real fill and [`part_ii_capacity_check`] budget the wrap against, so the two can
/// never disagree about what fits.
/// Part II's own line-1 usable width + a Part IV line's usable width, for `map`'s bundled asset —
/// shared by the real fill and [`part_ii_capacity_check`].
/// A free-text cell (geometry-exempt, page-derived): written + authorized only when non-empty. Mirrors
/// `form8283.rs::push_free` exactly — Form 8275 has no money-grid columns, so every cell here uses it.
/// Like [`push_free`], but the placement also joins a per-group strictly-descending-y ordinal sequence
/// (`FlatPlacement::free_ordered`) — used for Part IV's continuation lines, which (unlike every other
/// free-text write in this form) really are a physically ORDERED sequence the fill assumes is
/// top-to-bottom (round 2 finding 6).
/// Fill Form 8275 for `year` from the T13 printed disclosure + the FULL-RETURN filer's identity.
///
/// `Ok(None)` when `printed.part_i` is empty — there is no position to disclose (T13's
/// `disclosure_8275` already returns `None` upstream for a year with no promoted disposal leg, but a
/// defensive re-check here means this fill never emits a content-less "blank" 8275).
///
/// Refuses ([`FormsError::Overflow`]) when there are more Part I items than this revision's 6 rows —
/// v1 does not paginate Form 8275 (unlike Form 8283's `overflow::merge_copies`); a promoted year with
/// more than 6 disposal legs is a real but rare case, tracked as a follow-up rather than built here.
/// Fill Form 8275 for `year` for the **crypto-slice** `export-irs-pdf` path (Task 16) — NO filer
/// identity: mirrors `form8283::fill_form_8283`, which writes its property rows the same way (the
/// crypto slice never wrote an identity block; its 8275 rides beside a return btctax did not produce).
/// `Ok(None)` when `printed.part_i` is empty (no promoted disposal leg filed in `year`).
/// The map-parametrized fill (exposed via `testonly` for fault-injection KATs — mirrors
/// `fill_schedule_se_with_map` / `fill_1040_with_map`). Kept identity-REQUIRED (unlike
/// `fill_form_8283`'s `Option`) at this call surface — every existing caller (the full-return packet,
/// `sp4.rs`'s KATs) has one; the crypto-slice caller goes through [`fill_form_8275_slice`] instead.
/// The shared fill: `filer: None` (crypto-slice) skips the identity cells entirely, exactly as
/// `form8283::fill_form_8283_inner` does for its `filer: None` case.
/// Whether `narrative` fits, WITHOUT filling anything — the SAME wrap the real fill runs (via
/// [`part_ii_iv_widths`]/[`wrap_part_ii`], so the two can never disagree). `Ok(PartIiCapacity::Fits)`
/// covers an empty narrative too. Overflow is `Ok(PartIiCapacity::Overflow(_))`, not `Err` — it is an
/// expected, real outcome the caller builds ITS OWN refusal message from (naming the year, a remedy,
/// `--part-ii-file`); `Err` is reserved for an actual engine failure (an unsupported year, a bundled
/// map/PDF that fails to parse) the caller must still surface as such.
///
/// Exists so `btctax-cli`'s export paths (`crates/btctax-cli/src/cmd/admin.rs`,
/// `export_irs_pdf_from_session` + `export_full_return`) can refuse BEFORE `mkdir_out`/writing any
/// packet file — round 2 finding 2: without this, the crypto-slice path left an estimated-basis 8949
/// on disk with no 8275 PDF behind it when the narrative overflowed, because the overflow was only
/// discovered mid-write, inside `fill_form_8275_slice`, well after `basis_methodology.txt` and
/// `form_8275.txt` were already written.
/// The verdict [`part_ii_capacity_check`] returns.